What does (x^2) do in javascript? -
this question has answer here:
- javascript, ^ (caret) operator do? 5 answers
i writing calculations involving exponents in javascript , due habit of using carets in microsoft excel, typed x^2
in code. still gave me answer wasn't wanted. ^
in javascript?
alert(math.pow(3,2)); //result 9 alert(3^2); //result 1
that bitwise xor. use math.pow
exponents.
if 3^2 doing:
3 xor 2
computers use binary see
11 xor 10
put table:
11 1 ^ 0 = 1 10 1 ^ 1 = 0 -- 01
in simple terms:
xor take 2 numbers in binary, , bit true, must different
here's list of operators ^
math.pow()
takes base , exponent:
math.pow(3, 2)
--> 32 --> 9
math.pow(5, 6)
--> 56 --> 15,625
math.pow(7, 3)
--> 73 --> 343
Comments
Post a Comment