Here are 10 perplexing questions, each accompanied by a code snippet. To enhance your learning experience, answers are concealed within a {% details 💣 Reveal %} tag—click 'Reveal' to uncover them. Let's dive in! 🚀
Each correct answer will get 10 points. What's your score? 👀
Comment Down.
1. What will be the output of the following code?
console.log(0.1 + 0.2 === 0.3);
💣 Reveal
Reveal
false
This occurs due to floating-point precision errors in JavaScript. The expression 0.1 + 0.2 results in 0.30000000000000004, which is not strictly equal to 0.3.
3. What will be the output of this code?
console.log(typeof null);
💣 Reveal
Reveal
"object"
This is a well-known bug in JavaScript. The typeof operator returns "object" for null, even though null is not actually an object.
5. What will be the output of the following code?
console.log(1 < 2 < 3);
console.log(3 > 2 > 1);
💣 Reveal
Reveal
true
false
The first expression evaluates to true because 1 < 2 is true, and true < 3 is also true. The second expression evaluates to false because 3 > 2 is true, and true > 1 is false.
7. What will be the output of this code?
let a = [1, 2, 3];
let b = [1, 2, 3];
console.log(a == b);
console.log(a === b);
💣 Reveal
Reveal
false
false
In JavaScript, arrays are compared by reference, not by value. Since a and b are two different objects in memory, both comparisons return false.
9. What will be the output of the following code?
console.log(0 == false);
console.log(0 === false);
💣 Reveal
Reveal
true
false
The == operator performs type coercion, so 0 is considered equal to false. The === operator checks for both value and type, so 0 and false are not strictly equal.
These questions delve into JavaScript's quirks and common pitfalls. Understanding them will enhance your problem-solving skills and prepare you for technical interviews. Happy coding! 🎉
For a more in-depth exploration of JavaScript interview questions, check out this
SOCIAL SHARE CARD GENERATOR