Home > Article > Web Front-end > How to use javascript sqrt method
The javascript sqrt method is used to return the square root of a number. Its usage syntax is "Math.sqrt(x)". Its parameter x represents a number and must be a number greater than or equal to 0.
The operating environment of this article: Windows 7 system, javascript version 1.8.5, DELL G3 computer
The sqrt() method can return the square root of a number.
Syntax
Math.sqrt(x)
Parameters
x Required. Must be a number greater than or equal to 0.
Return value
The square root of parameter x. If x is less than 0, returns NaN.
Tips and Notes
Tips: The Math.pow() method can calculate any root of a number.
Example
In this example, we will return the square roots of different numbers:
var a=Math.sqrt(0); var b=Math.sqrt(1); var c=Math.sqrt(9); var d=Math.sqrt(0.64); var e=Math.sqrt(-9);
Output:
0 1 3 0.8 NaN
[Recommended learning: js Basic tutorial】
The above is the detailed content of How to use javascript sqrt method. For more information, please follow other related articles on the PHP Chinese website!