raise to power javascript code example
Example 1: javascript squared
Math.pow(x1, 2)
x1 * x1
x1 ** 2
Example 2: exponent in javascript
let number = 2;
let exponent = 3;
console.log( number ** exponent);
console.log( Math.pow(number, exponent);
Example 3: get recursion exponent power in javascript
const potenciacion=(base,exponente)=>{
if(exponente==1){
return base;
}
if(exponente==0){
return 1;
}
if(exponente<0){
exponente*=(-1);
return 1/(potenciacion(base,exponente-1) * base);
}
return potenciacion(base,exponente-1) * base;
}
console.log(potenciacion(2,2));