4 ms·
Another way to cast to a Number is the bitwise-or operator. It has the useful property of always yielding a number. '42' | 0; // 42 NaN | 0;
by bluesnowmonkey 11y ago
Another way to cast to a Number is the bitwise-or operator. It has the useful property of always yielding a number.
'42' | 0; // 42
NaN | 0; // 0
null | 0; // 0
undefined | 0; // 0
false | 0; // 0
true | 0; // 1