What is the logic of bitwise operators on undefined???
var x;
console.log(x); // undefined
console.log(x^7); // 7
console.log(7^x); // 7
console.log(x|7); // 7
console.log(7|x); // 7
console.log(7&x); // 0
console.log(x&7); // 0
console.log(~x); // -1
console.log(x*2); // NaN
console.log(x/2); // NaN
console.log(x+2); // NaN
console.log(x-2); // NaN
I can see some sense in NaN. Because undefined -2 is really 'not a number'. But I do not follow any logic on bitwise operators and undefined.
The internal function [ToInt32]
is called on all operands for all bitwise operators.
Note that ToInt32(undefined) -> 0
and the range is [0, 2^32)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With