Answers of Front-end Job Interview Coding Questions

Onur Dayıbaşı
Frontend Development With JS
2 min readJul 1, 2019

Question: What is the value of foo?

var foo = 10 + '20';console.log(foo);   //Result '1020' because its string concat operation

Question: What will be the output of the code below?

console.log(0.1 + 0.2 == 0.3);console.log(result);  //Result false because float keep binary in mem so when convert 0.1 or 0.2 to binary its not same 0.1 0.10000000001 etc.

Question: How would you make this work?

add(2, 5); // 7
add(2)(5); // 7
const add=(a, b)=>{
if(a && b) return a+b;
else return buffAdd=(b)=>{return a+b}
};
console.log(add(2, 5));
console.log(add(2)(5));

Question: What value is returned from the following statement?

"i'm a lasagna hog".split("").reverse().join("");const stringOpsResult="i'm a lasagna hog".split("").reverse().join("");
console.log(stringOpsResult);
//goh angasal a m'i. how ? splits generates 17 char array all char reverse then the string generate

//if we split(" ") and join(" ") this time we generate 4 word array and we reverse word hog lasange a i'm

Question: What is the value of window.foo?

( window.foo || ( window.foo = "bar" ) );
console.log(window.go); //Result is 'bar' if we use && then second command not work so window.foo=undefined

Question: What is the outcome of the two alerts below?

var foo = "Hello"; (function() 
{var bar = " World"; alert(foo + bar);})(); //Alert=> Hello World
alert(foo + bar); // Reference Error bar is not defined

Question: What is the value of foo.length?


var foo = [];
foo.push(1);
foo.push(2);
console.log(foo.length); //Results is 2

Question: What is the value of foo.x?

var foo = {n: 1};
var bar = foo;
foo.x = foo = {n: 2}; //foo.x = (foo = {n:2}); => {n:1}.x = ( {n:1} = {n:2} ); R.H.S. foo={n:2}
console.log(foo.x); //Result undefined
console.log(foo); //Result {n:2}
console.log(bar); //Result {n:1, x: {n:2}}
Result = undefined

Question: What does the following code print?

console.log(‘one’);
setTimeout(function() {
console.log(‘two’);
}, 0);
Promise.resolve().then(function() {
console.log(‘three’);
})
console.log(‘four’);
//Result one, four , three, two its easy for one and four but theb why first three and then two prints.
//All of timeout and promise is async func..
//Answers is timeout in EventLoop Queue , promise process in JobQueue and JobQueue is high priority…

Question: What is the difference between these four promises?

//One level difficult..
//The answer https://gist.github.com/nolanlawson/940d1a390b2d9cf9483c

Promises answers

Uzun süredir farklı sektörlerde (Askeri, Telekomünikasyon, Devlet, Bankacılık, Sigortacılık, Tübitak, SaaS) yazılımlar geliştiriyorum. Bu süreçte Havelsan, Milsoft, T2, Cybersoft ve Thundra firmalarında yönetici ve yazılım mühendisi olarak çalıştım. Deneyimlerimi ve teknolojik bilgi birikimi mi olabildiğince OnurDayibasi.com adresinde toplamaya çalışıyorum. Tüm yazılarıma ve daha fazlasını bu site üzerinden erişebilirsiniz.

--

--