Name
Math.sqrt( ): compute a square root â ECMAScript v1
Synopsis
Math.sqrt(x
)
Arguments
-
x
A numeric value greater than or equal to zero.
Returns
The square root of x
. Returns
NaN
if
x
is less than zero.
Description
Math.sqrt( )
computes the
square root of a number. Note, however, that you can compute
arbitrary roots of a number with Math.pow(
)
. For example:
Math.cuberoot = function(x){ return Math.pow(x,1/3); } Math.cuberoot(8); // Returns 2
Get JavaScript: The Definitive Guide, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.