I am trying to figure out this operator on JS -
'string' ^= 'string';
But I can not find ant information. Is that a comparison or assignment ?
Thanks.
The strict equality operator ( === ) checks whether its two operands are equal, returning a Boolean result.
The Complete Full-Stack JavaScript Course! The “double tilde” (~~) operator is a double NOT Bitwise operator. Use it as a substitute for Math. floor(), since it's faster.
The === operator means "is exactly equal to," matching by both value and data type. The == operator means "is equal to," matching by value only.
The main difference between the == and === operator in javascript is that the == operator does the type conversion of the operands before comparison, whereas the === operator compares the values as well as the data types of the operands.
myVar ^= 5
is the same as myVar = myVar ^ 5
. ^
is the bitwise xor
operator
Let's say myVar
was set to 2
Exclusive "or" checks the first bit of both numbers and sees 1,0 and returns 1 then sees 0,1 and returns 1 and sees 1,0 and returns 1.
Thus 111 which converted back to decimal is 7
So 5^2
is 7
var myVar = 2;
myVar ^= 5;
alert(myVar); // 7
^
(caret) is the Bitwise XOR (Exclusive Or) operator. As with more common operator combinations like +=
, a ^= b
is equivalent to a = a^b
.
See the Javascript documentation from Mozilla for more details.
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