What Does ** Do in JavaScript?

Find out what double asterisks mean in JavaScript

In JavaScript, "**" represents the exponentiation operator, which returns the result of raising the first operand to the power of the second operand:

// ES7+
console.log(2 ** 10); // 1024

This is the same as using the Math.pow() method:

console.log(Math.pow(2, 10)); // 1024

However, one big difference between Math.pow() and ** is the fact that the latter works with bigints as well (as opposed to the former that does not work with bigint values):

// ES10+
console.log(2n ** 10n); // 1024n
// ES10+
// TypeError: Cannot convert a BigInt value to a number
console.log(Math.pow(2n, 10n));

The "n" at the end of a number merely suggests that the number is a bigint primitive.


Hope you found this post useful. It was published . Please show your love and support by sharing this post.