What does | do in Javascript? Is it similar to the logical or operator ||
? I have seen it being used to apparently convert strings to numbers. How does this work?
var x = '12345';
var num = x|0;
console.log(num);
What does | do in Javascript? Is it similar to the logical or operator ||
? I have seen it being used to apparently convert strings to numbers. How does this work?
var x = '12345';
var num = x|0;
console.log(num);
It's a bitwise OR |
. Sometimes misused (64 bit float vs 32 bit integer) for getting integer values.
var x = '12345.678',
num = x | 0;
console.log(num);