tags:

views:

70

answers:

3
<script>
a = 3;
a = a^a // a = 27
</script>

is there something like that:

+13  A: 

Math.pow:

var a = 3;
a = Math.pow(a, a);
Darin Dimitrov
A: 

^ is called XOR.

http://en.wikipedia.org/wiki/Exclusive_or

oneat
Unfortunately, mathematicians also use `x^y` as a shortform in ASCII text to mean x raised to the power of y. You need to understand the context to answer this question correctly since `3 XOR 3` does not equal 27.
slebetman
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
*/
kennebec