JavaScript Math sqrt() method

The JavaScript math sqrt() method returns the square root of a number. If the provided number is negative, it returns NaN.

Syntax

The sqrt() method is represented by the following syntax:

Parameter

num - A number.

Return

The square root of the given number.

JavaScript Math sqrt() method example

Here, we will understand sqrt() method through various examples.

Example 1

Let's see an example to print square root of the given numbers.

Test it Now

Output:

4
3.4641016151377544

Example 2

Let's see some cases where sqrt() method returns NaN.

Test it Now

Output:

NaN
NaN

Example 3

Here, you can test sqrt() method with your own test cases.

Test it Now
Next TopicJavaScript Math