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

How to use javascript sqrt method

藏色散人
Release: 2023-01-03 09:32:00
Original
3373 people have browsed it

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)
Copy after login

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);
Copy after login

Output:

0
1
3
0.8
NaN
Copy after login

[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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template