Javascript power 0 odd result?

im using chrome with this code:

var startbet = 1; var shot = 0; var bet = startbet * 2^shot; 

n ^ 0 = n in this case
it must be equal to 1 regardless of n

is this a bug with javascript or do some people who believe in the power of 0 have to be treated differently?

+4
source share
2 answers

In Javascript, the ^ operator is a bitwise XOR , not an exponent.

As Michael says, you should use Math.pow () to calculate metrics.

+7
source

I think you need instead of Math.pow

+5
source

Source: https://habr.com/ru/post/1435839/


All Articles