JavaScript Tricky Questions & Answers (Sample)
1. What is the output of '0.1 + 0.2 === 0.3'?
Answer: false. Due to floating-point precision issues in JavaScript.
2. What is the type of 'null' in JavaScript?
Answer: 'object'. This is a long-standing bug in JavaScript.
3. What will '[] + {}' return?
Answer: "[object Object]". An empty array is coerced to an empty string, and {} is coerced to "[object
Object]".
4. What will '{} + []' return?
Answer: 0. The expression is interpreted as a code block and unary plus applied to an empty array.
5. Can you explain 'NaN === NaN'?
Answer: false. NaN is not equal to anything, including itself.
6. What is 'typeof NaN'?
Answer: 'number'. NaN stands for 'Not a Number' but is actually of type 'number'.
7. What is the difference between '==' and '==='?
Answer: '==' allows type coercion, '===' does not.
8. What is hoisting?
Answer: Variables and function declarations are moved to the top of their scope during compilation.
9. Is 'var x = y = 1;' valid? What does it do?
Answer: Yes. y becomes a global variable (if not in strict mode). x is declared with var.
10. What is the output of 'typeof typeof 1'?
Answer: 'string'. typeof 1 returns 'number', and typeof 'number' is 'string'.
... (This format continues up to 370 entries in the full version)