raise to power javascript code example

Example 1: javascript squared

//squared numbers

Math.pow(x1, 2)
x1 * x1
x1 ** 2                  // ES6 syntax

Example 2: exponent in javascript

let number = 2;
let exponent = 3;

//using the exponent operator
console.log( number ** exponent);
// using the Math library 
console.log( Math.pow(number, exponent);
// these will both output 8

Example 3: get recursion exponent power in javascript

//get recursion exponent power in javascript
//calcular potencia en 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));