Implement an exponent function

The Exponentiation Operator explained using Math.pow

If you want to do computation to any power in today's Javascript, there is no point avoiding the Math.pow function. With this, you can pass in a base and an exponent and you will get in return the result of raising that base to the power exponent. Here are some examples:


var squared = function(x) {
	return Math.pow(x, 2);
}

var cubed = function(x) {
	return Math.pow(x, 3);
}

var fourthPower(x) {
	return Math.pow(x, 4);
}

// OR USING ES6 -

const squared = x => Math.pow(x, 2);
const cube = x => Math.pow(x, 3);
const fourthPower = x => Math.pow(x, 4);

// RESULTS
square(4)
// 16
cube(8)
// 512
fourthPower(5)
// 625