Home  >  Article  >  Web Front-end  >  How to use javascript sqrt method

How to use javascript sqrt method

藏色散人
藏色散人Original
2021-03-31 11:38:303246browse

The javascript sqrt method is used to return the square root of a number. Its usage syntax is "Math.sqrt(x)". Its parameter x represents a number and must be a number greater than or equal to 0.

How to use javascript sqrt method

The operating environment of this article: Windows 7 system, javascript version 1.8.5, DELL G3 computer

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

Syntax

Math.sqrt(x)

Parameters

x Required. Must be a number greater than or equal to 0.

Return value

The square root of parameter x. If x is less than 0, returns NaN.

Tips and Notes

Tips: The Math.pow() method can calculate any root of a number.

Example

In this example, we will return the square roots of different numbers:

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

Output:

0
1
3
0.8
NaN

[Recommended learning: js Basic tutorial

The above is the detailed content of How to use javascript sqrt method. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn