Exponentiation
The exponentiation operator a ** b raises a to the power of b.
/**
* The exponentiation operator a ** b raises a to the power of b
* Power of 1/2 is the same as square root
* Power of 1/3 is the same as cubic root
*/
console.log(2 ** 3); // 8
console.log(4 ** 1/2); // 2
console.log(8 ** 1/3); // 2
console.log(2 ^ 3); // 1 - XOR bitwise
console.log(2 ^ 2); // 0
console.log(3 % 2); // 1 - reminder
console.log(8 % 3); // 2
Unary +
If the operand is not a number, the unary plus converts it into a number.
/**
* The unary operator (+) applied to a single value
* It doesn’t do anything to numbers
* It converts the string to number
*
* Unary pluses applied to values before the binary ones ...
* because of their higher precedence
*/
let a = 1;
let b = true;
let x = "2";
let y = "3";
console.log( +a ); // 1
console.log( +b ); // 1
console.log( +x + +y ); // 5
Last update: 357 days ago