Because the toNumber
conversion of any string that is comprised only of white space (or if it's empty) results in 0
.
console.log(Number("\n")); // 0
The parseInt/Float
methods actually require some numeric content to be converted, though it'll allow leading spaces, and trailing garbage.
console.log(parseFloat(" 123.45odsifjj")); // 123.45
The toNumber conversion is defined in 9.3.1 ToNumber Applied to the String Type.
A StringNumericLiteral that is empty or contains only white space is converted to +0