Data Structures & AlgorithmsVery hardGoogle · Flipkart interview

Edge case: JavaScript type coercion.

Edge case: JavaScript type coercion.
console.log(typeof null, [] + {}, [] == ![], 0.1 + 0.2 === 0.3);
What is printed?
  1. A. object [object Object] false false
  2. B. null [object Object] true false
  3. C. object true true
  4. D. object [object Object] true false

Correct answer: D. object [object Object] true false

typeof null is 'object' (a historical quirk). [] + {} converts both to strings: '' + '[object Object]'. ![] is false; [] == false converts both sides to numbers (0 == 0), so true. 0.1 + 0.2 is 0.30000000000000004 in binary floating point.

More Coding Interview Problems questions

Exams that ask this topic