JavaScript sqrt() method

Definition and usage

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

Instance

Example 1

Return the square root of a number:

Math.sqrt(9);

Try it yourself

Example 2

Return the square root of different numbers:

var a = Math.sqrt(0);
var b = Math.sqrt(1);
var c = Math.sqrt(9);
var d = Math.sqrt(64);
var e = Math.sqrt(-9);

Try it yourself

Syntax

Math.sqrt(x)

Parameter value

Parameter Description
x Required. Number.

Technical details

Return value: Value. If x is negative, it returns NaN.
JavaScript Version: ECMAScript 1

Browser Support

Method Chrome IE Firefox Safari Opera
sqrt() Support Support Support Support Support

Related Pages

Tutorial:JavaScript Mathematics