// Function to calculate the power of a number
function calculatePower(base, exponent) {
return Math.pow(base, exponent);
}
// Example: Calculate the power of 2 raised to the 3rd exponent
const result = calculatePower(2, 3);
// Log the result to the console
console.log('Power of Number:', result);
code
JavaScript Power Calculation
This JavaScript code defines a function calculatePower that uses the Math.pow method to calculate the power of a given base raised to a specified exponent. The example calculates the power of 2 raised to the 3rd exponent, and the result is logged to the console. The comments provide explanations for each part of the code.
Math
Power Calculation