sqrt

Returns the square root of a number.

Applies to

Math

Syntax

sqrt(x)

Parameters

x

A number.

Description

If the value of number (x) is outside the required range,sqrt returns 0.

sqrt is a static method of Math. As a result, you always use it as Math.sqrt(), rather than as a method of a Math object you create.

Examples

The following function returns the square root of the variable x:

function getRoot(x) {
      return Math.sqrt(x)
}

If you pass getRoot the value 9, it returns 3; if you pass it the value 2, it returns 1.414213562373095.