DEV Community

Anjali Gurjar
Anjali Gurjar

Posted on

JS Tricky question

What will the following output?
console.log(0.1 + 0.2 === 0.3);
Answer: false
Explanation:
In JavaScript (and most programming languages), floating-point arithmetic isn’t always precise.
0.1 + 0.2 results in 0.30000000000000004, not exactly 0.3.

  1. What’s the output? console.log([] + []); console.log([] + {}); console.log({} + []); Answer:

""
"[object Object]"
0
Explanation:

[] + [] returns an empty string because JavaScript converts arrays to strings during concatenation.
[] + {} becomes "[object Object]" because {} is converted to its string representation.
{} when placed at the beginning of a line is interpreted as a block, so {} + [] returns 0.

  1. What will this code log? console.log(typeof null);

Top comments (0)