totn JavaScript

JavaScript: Math pow() function

This JavaScript tutorial explains how to use the math function called pow() with syntax and examples.

Description

In JavaScript, pow() is a function that is used to return m raised to the nth power. Because the pow() function is a static function of the Math object, it must be invoked through the placeholder object called Math.

Syntax

In JavaScript, the syntax for the pow() function is:

Math.pow(m, n);

Parameters or Arguments

m
The number used as the base in the calculation.
n
The number used as the exponent in the calculation.

Returns

The pow() function returns m raised to the nth power which is mn.

Note

  • Math is a placeholder object that contains mathematical functions and constants of which pow() is one of these functions.

Example

Let's take a look at an example of how to use the pow() function in JavaScript.

For example:

console.log(Math.pow(5, 2));
console.log(Math.pow(5, -2));
console.log(Math.pow(4.6, 3));

In this example, we have invoked the pow() function using the Math class.

We have written the output of the pow() function to the web browser console log, for demonstration purposes, to show what the pow() function returns.

The following will be output to the web browser console log:

25
0.04
97.33599999999997

In this example, the first output to the console log returned 25 which is the calculation of 52.

The second output to the console log returned 0.04 which is the calculation of 5-2.

The third output to the console log returned 97.33599999999997 which is the calculation of 4.63.