Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. JavaScript
  3. Reference
  4. Standard built-in objects
  5. Math
  6. sqrt()

Math.sqrt()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

TheMath.sqrt() static method returns the square root of a number. That is

x0,𝙼𝚊𝚝𝚑.𝚜𝚚𝚛𝚝(𝚡)=x=the unique y0 such that y2=x\forall x \geq 0,\;\mathtt{\operatorname{Math.sqrt}(x)} = \sqrt{x} = \text{the unique } y \geq 0 \text{ such that } y^2 = x

Try it

function calcHypotenuse(a, b) {  return Math.sqrt(a * a + b * b);}console.log(calcHypotenuse(3, 4));// Expected output: 5console.log(calcHypotenuse(5, 12));// Expected output: 13console.log(calcHypotenuse(0, 0));// Expected output: 0

Syntax

js
Math.sqrt(x)

Parameters

x

A number greater than or equal to 0.

Return value

The square root ofx, a nonnegative number. Ifx < 0, returnsNaN.

Description

Becausesqrt() is a static method ofMath, you always use it asMath.sqrt(), rather than as a method of aMath object you created (Math is not a constructor).

Examples

Using Math.sqrt()

js
Math.sqrt(-1); // NaNMath.sqrt(-0); // -0Math.sqrt(0); // 0Math.sqrt(1); // 1Math.sqrt(2); // 1.414213562373095Math.sqrt(9); // 3Math.sqrt(Infinity); // Infinity

Specifications

Specification
ECMAScript® 2026 Language Specification
# sec-math.sqrt

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2026 Movatter.jp