JavaScript | Math.sqrt( ) function
The Math.sqrt() function in JavaScript is used to square root of the number passed as parameter to the function.
Syntax
Math.sqrt(value)
Parameters: This function accepts a single parameter value which hold the number whose square root is to be calculated.
Returns: Square root of the number passed as parameter passed as parameter.
Example:
Input : Math.sqrt(4) Output : 2 Input : Math.sqrt(-4) Output : NaN
Errors and Exceptions:
- A non-numeric string passed as parameter returns NaN
- An array with more than 1 integer passed as parameter returns NaN
- A negative number passed as parameter returns NaN
- An empty string passed as parameter returns NaN
- An empty array passed as parameter returns NaN
Below are some examples that illustrate the Math.floor() function in JavaScript:
- Example 1:
<!-- NEGATIVE NUMBER EXAMPLE --><scripttype="text/javascript">document.write(Math.sqrt(-2) + "<br>");document.write(Math.sqrt(-2.56));</script>chevron_rightfilter_noneOutput:
NaN NaN
- Example 2:
<!-- POSITIVE NUMBER EXAMPLE --><scripttype="text/javascript">document.write(Math.sqrt(2) + "<br>");document.write(Math.sqrt(2.56));</script>chevron_rightfilter_noneOutput:
1.4142135623730951 1.6
- Example 3:
<!-- STRING EXAMPLE --><scripttype="text/javascript">document.write(Math.floor("Geeksforgeeks"));</script>chevron_rightfilter_noneOutput:
NaN
- Example 4:
<!-- ADDITION INSIDE FUNCTION EXAMPLE --><scripttype="text/javascript">document.write(Math.floor(7.2+9.3));</script>chevron_rightfilter_noneOutput:
4.06201920231798
- Google Chrome
- Internet Explorer
- Firefox
- Opera
- Safari
- How to call a function that return another function in JavaScript ?
- JavaScript | Function Parameters
- JavaScript | Function Definitions
- JavaScript | toString( ) function
- JavaScript | Math.pow( ) Function
- JavaScript | Array every() function
- JavaScript | String() Function
- JavaScript | Function Apply
- JavaScript | Function Call
- Javascript | Number() Function
- JavaScript | Math.E() function
- JavaScript | Array some() function
- JavaScript | toFixed( ) Function
- JavaScript | Array.of() function
- JavaScript | Math.abs( ) function
Supported Browsers: The browsers supported by JavaScript Math.sqrt( ) function are listed below:
Recommended Posts:
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



