Your product could be here, in front of thousands of JavaScript developers. Sponsor this spot →
JavaScript Quiz

What is the difference between parseInt and Number?

Do you know what will be the output of this code?

JavaScript
console.log(parseInt("08.9px"), Number("08.9px"));
Show answer and explanation

The answer is 8 NaN.

parseInt parses as far as it can and stops at ., so it returns 8. Number requires the whole string to be a valid number, and "px" makes it NaN.

Take the full quiz Next question →

More Type Coercion questions

  1. Why is typeof NaN "number" in JavaScript?
  2. Why does 018 - 015 equal 5 in JavaScript?
  3. Why is 0.1 + 0.2 == 0.3 false in JavaScript?
  4. Why is Math.max() < Math.min() true?
  5. What is -7 % 3 in JavaScript?

Related topics