The Wayback Machine - https://web.archive.org/web/20250108163256/https://www.geeksforgeeks.org/javascript-math-sqrt-method/
Open In App

JavaScript Math sqrt() Method

Last Updated : 15 Jul, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

The JavaScript Math sqrt( ) Method in JavaScript is used to square the root of the number passed as a parameter to the function. 

Syntax:

Math.sqrt(value)

Parameters:

This method accepts a single parameter as mentioned above and described below: 

  • Value: which holds the number whose square root is to be calculated.

Return Value:

The square root of the number is passed as a parameter.

Example 1: Below is an example of the Math sqrt() Method. 

javascript
console.log(Math.sqrt(-2));
console.log(Math.sqrt(-2.56));        

Output
NaN
NaN

Example 2:

JavaScript
console.log(Math.sqrt(4));
console.log(Math.sqrt(256));        

Output
2
16

We have a complete list of Javascript Math Objects methods, to check those please go through this Javascript Math Object Complete reference article.

Supported Browsers: 

  • Chrome 51
  • Edge 15
  • Firefox 54
  • Safari 10
  • Opera 38

JavaScript Math sqrt() Method – FAQs

What is the Math.sqrt() method in JavaScript?

The Math.sqrt() method returns the square root of a given number.

Are there any common use cases for Math.sqrt()?

Common use cases for Math.sqrt() include calculating the length of the hypotenuse in a right triangle, solving quadratic equations, and performing other mathematical operations that require square roots.

What is the return type of Math.sqrt()?

The Math.sqrt() method returns a number that is the square root of the input. If the input is negative, it returns NaN.

Can Math.sqrt() handle zero as an input?

Yes, Math.sqrt(0) returns 0 since the square root of zero is zero.

We have a Cheat Sheet on Javascript where we covered all the important topics of Javascript to check those please go through Javascript Cheat Sheet-A Basic guide to JavaScript.


Next Article

Similar Reads

three90RightbarBannerImg