Javascript js中的三个或更多根目录 a=3; a=a^a//a=27

Javascript js中的三个或更多根目录 a=3; a=a^a//a=27,javascript,Javascript,有这样的事吗:: ^被称为XOR 不幸的是,数学家也将x^y用作ASCII文本中的缩写,表示x提升到y的幂。你需要理解上下文才能正确回答这个问题,因为3xor 3不等于27。你的意思是,不是root。 <script> a = 3; a = a^a // a = 27 </script> var a = 3; a = Math.pow(a, a); // You can pass '3^3' to a method if you like- Math.toPow=

有这样的事吗:

^被称为XOR


不幸的是,数学家也将
x^y
用作ASCII文本中的缩写,表示x提升到y的幂。你需要理解上下文才能正确回答这个问题,因为
3xor 3
不等于27。你的意思是,不是root。
<script>
a = 3;
a = a^a // a = 27
</script>
var a = 3;
a = Math.pow(a, a);
// You can pass '3^3' to a method if you like-

Math.toPow= function(s){
    s= s.split('^');
    return Math.pow(+s[0], +s[1]);
}

// or to validate input-

Math.toPow= function(s){
    s= s.split('^');
    try{
        return Math.pow(+s[0], +s[1]);
    }
    catch(er){
        return NaN;
    }
}

Math.toPow('3^3')

/*  returned value: (Number)
27
*/

// I prefer to use Math.pow(3,3)
Math.pow(3,3)

/*  returned value: (Number)
27
*/