• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
JavaScriptSource

JavaScriptSource

Search 5,000+ Free JavaScript Snippets

  • Home
  • Browse Snippets
    • Addon
    • Ajax
    • Buttons
    • Cookies
    • CSS
    • Featured
    • Forms
    • Games
    • Generators
    • Image Effects
    • Math Related
    • Miscellaneous
    • Multimedia
    • Navigation
    • Page Details
    • Passwords
    • Text Effects
    • Time & Date
    • User Details
Home / Basics / The JavaScript function Math.pow()

The JavaScript function Math.pow()

The JavaScript function Math.pow()

The Math.pow() function in JavaScript is used to raise a number (called the base) to a certain power (called the exponent). The syntax for using this function is Math.pow(base, exponent). For example, to raise 2 to the power of 3, you would use the following code:

console.log(Math.pow(2, 3)); // prints 8

In this example, 2 is the base and 3 is the exponent. The function returns the result of 2 raised to the power of 3, which is 8.

You can also use variables as the base and exponent. For example:

let base = 2;
let exponent = 4;
console.log(Math.pow(base, exponent)); // prints 16

In this example, the value of base is 2 and the value of exponent is 4. The function returns the result of 2 raised to the power of 4, which is 16.

It’s also important to note that the base and exponent can be decimal numbers.

console.log(Math.pow(2.5, 3)); // prints 15.625

In this example, 2.5 is the base and 3 is the exponent. The function returns the result of 2.5 raised to the power of 3, which is 15.625

You can also use Math.pow() to find the square root of a number by passing in the number as the base and 0.5 as the exponent.

console.log(Math.pow(4, 0.5)); // prints 2

In this example, 4 is the base and 0.5 is the exponent. The function returns the square root of 4, which is 2

In conclusion, the Math.pow() function in JavaScript is a useful tool for performing exponential calculations. It is a simple function to use, and it allows you to raise a number to a certain power with ease.

Basics, Math Related

Related Snippets:

  • JavaScript Operators Explained
  • How To Convert a String to Boolean in JavaScript
  • Calculate the nth root of a given number
  • The onabort Event in JavaScript

Primary Sidebar

Popular Posts

Story Generator

IP Grabber – get a users IP address with JavaScript

Simple Calendar

Remove Ads

Astrological Calculator

Copyright © 2025 JavaScriptSource.com

  • About
  • Privacy Policy
  • FAQ
  • Jobs For Developers