JavaScript Interview Questions that made me think — Do I really know JavaScript? — Part 3

Javascript tricky interview questions

What will be printed in the console?

Error will be thrwon in the console:

Uncaught SyntaxError: identifier starts immediately after numeric literal
21..toString(); // "21";

(21).toString(); // "21";

What will be printed in the console?

4520, 92
So First operation is obivious, whenever we do add(+) operation with string,
JS will concatanate the string.

But for ++ what went different?

It's the implementation of ++ and ++, both of these first convert the argument
to Number and then do a ++.

function plusplus(number) {
const num = Number(number);
num = num+1;
return num';
}

What will be printed in the console?

true

Let's break it down.

Whenever we do a double equality check, JS engine will try to convert both
values in Number.

Number([]) == Number(![]);
0 == Number(false); // ![] will give false
0 == 0 // true

What will be returned from the function?

90000

Here if we break down this as,

const res = cosmic = 90000;
return res;

// Undeclared cosmic will be added to global scrope and 90000 will be returned.

What will be logged in the console?

Water Added
Uncaught TypeError: addSugar is not a function

What will be printed in the console?

3, Hello

this is pointing to array itself, and the length of array is 3.

What will be logged in the console?

[ 10, 20, 3, 7 ]
[ 10, 20, 3, 7 ].sort((a, b) => a - b); //[ 3, 7, 10, 20]

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store