$ ./guess_the_languageProblem Solving — predict the output
Problem Solving — predict the output · hard · #192

What is the output?

const o = { valueOf: () => 2 };
console.log(o + 1);
  1. 3
  2. 21
  3. NaN
  4. Error
Coercion tries valueOf before toString, so the object becomes the number 2.
Play Problem Solving ▸