Javascript - Math sqrt() Method

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

Description

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

Syntax

Math.sqrt(x)

Parameter Values

Parameter Require Description
x Required. A number

Return

A Number. If x is a negative number, NaN is returned

Example

Return the square root of a number:

Demo

//display the square root of 9.
console.log(Math.sqrt(9));//  ww  w . j a  v  a 2  s  .co m

//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);

var x = a + "\n" + b + "\n" + c + "\n" + d + "\n" + e;
console.log(x);

Result