<script>
a = 3;
a = a^a // a = 27
</script>
有类似的东西:
答案 0 :(得分:13)
var a = 3;
a = Math.pow(a, a);
答案 1 :(得分:0)
// 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
*/
答案 2 :(得分:-1)