JavaScript interview questions
console.log("5" > "11") =>true
console.log("5" > 11) =>false
console.log(" " > -1) =>true
console.log("you " > 1) =>false
Ans: for string letter by letter comparison takes place, when values of different types are compared, and they get converted into numbers, here empty string will be converted into 0 , and "you" becomes NaN, which is neither greater than nor less than, or any numconst Person = { name:"puja" , age"23" , name:"broooo" }
Ans:-if a var is overridden then the memory will be dedicated to the last valueconst Person1 = {name:"puja", age:23 },const Person2 = {name:"puja", age:23}
consoe.log(Person1 == person2) =>false
consoe.log(Person1 == person2) =>false
Ans: they both have different memory allocation(=== check for the same value )convert a multidimensional array into a single array
Ans: there are 3 ways ------flat , reduce, spread
const answer = (numbers) =>{
return numbers.reduce(acc, curr) =>{
return acc.concat(Array.isArray(curr) ? answer(num) : num ) ,
},[] ) }
console.log(numbers.flat(Infinity))
console.log(1+2+"3" +4+5) => 3345
consol.elog(1+2+3+"1") =>61
Ans: When string and integer together concat happen, otherwise addAccessing a block scope variable before its declaration results in a Reference error. This is known as the "temporal dead zone." Even though the variable exists in the scope, accessing it before its declaration or initialization results in an error.
for(var I = 0 ; I<3 ; i++){setTimeout(() =>consoele.log(i) , 100 )
since var is global var the time the first loop will be completed I value will be 3 sp 3 will be rint everytime
Subscribe to my newsletter
Read articles from Puja Debnath directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by