JavaScript中计算N次方的方法**和math.pow()-讲解
指数运算符(**)
console.log(2 ** 2); // 4
console.log(3 ** 2); // 9
console.log('3' ** '2'); // 9
console.log((() => {
    let x = 2;
    let y = 3;
    x **= y;
    return x;
})()); // 8Math.pow()
返回基础的指数次幂
Math.pow(x, y) //x:基数 y:指数
console.log(Math.pow(2, 2)); // 4
console.log(Math.pow(3, 2)); // 9
console.log(Math.pow('3', '2')); // 9
let x = 2;
x = Math.pow(x, 3);
console.log(x); // 8
本文来自博客园,作者:JackieDYH,转载请注明原文链接:https://www.cnblogs.com/JackieDYH/p/17634260.html

 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号