Find your content:

Search form

You are here

Advanced javascript interview questions - Help Interview ( Google & Amazon)

 
Share

Advanced javascript interview questions - Help Interview ( Google, Amazon & Facebook)

 

Question1:

console.log(2+"2"); // Answer is 22 - Since right operand is string it gets concatenated.

console.log(2-'2'); // Answer is  0 - because javascript convert string to number and do the arithmetic operation.

 

Question2:

let num = [1,2,2,3]; // Find the duplicate in single line of code without using map, forloop and etc...?

Ans: console.log([...new Set(num)]);

 

Question3:

console.log( 5 < 6 < 7); // true - why?

console.log( 7 > 6 > 5); // false - why? - 

Ans:  5 < 6  returns true then console.log(true < 7); // true will be replaced by 1 so final output is true

          7 > 6  returns true then console.log( true > 5); // true will be replaced by 1 so (1 > 5) it returns false

Question4:

let a =() => { return arguments};

console.log(a('hi')); // arguments won't work in arrow function. If it is a regular function you get 'hi'

 

Question5:

 let x =function(){

return

{

 "message":"hi";

}

}

console.log(x()); // result is undefined because return statement will be enclosed with ; if nothing is present.

 

Question6:

let profile = { name: "test"

};

profile.age = 3;

console.log(profile); // profile gets added age property.

Question here is how you prevent to add new properties to the object?

Ans: Object.freeze(profile);

add  profile.city = "SFO" 

console.log(profile); // you won't see city.

 

Question7:

Followup on question6: how do you modify the existing property?

If you are using Object.freeze(profile) it won't allow you to modify or add. If you want to modify use Object.seal(profile) it allows you to modify the data.

 

Question8:

let profile = {

  name:"tech";

}

Object.defineProperty(profile, 'age',{value:3, writable:false});

//you cannot change age property value.

 

Question9

console.log(Math.max()); // -Infinity why?

Ans: lets say console.log(Math.max(1,2,3)) what it does is

It checks with lowest integer(-Infinity) with 1 then 1 is greater next step is

It checks with 1 with 2 it produces 2 is greater then 2 with 3 it produce 3 is greater. What happen for console.log(Math.max())? - No number provided is default is -Infinity

 

 

My Block Status

My Block Content