Movatterモバイル変換


[0]ホーム

URL:


  1. 開発者向けのウェブ技術
  2. JavaScript
  3. JavaScript リファレンス
  4. 標準組み込みオブジェクト
  5. Math
  6. sqrt()

このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docsコミュニティーについてもっと知り、仲間になるにはこちらから。

View in EnglishAlways switch to English

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 ⁨2015年7月⁩.

Math.sqrt() は静的メソッドで、ある数の平方根を返します。

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

試してみましょう

function calcHypotenuse(a, b) {  return Math.sqrt(a * a + b * b);}console.log(calcHypotenuse(3, 4));// 予想される結果: 5console.log(calcHypotenuse(5, 12));// 予想される結果: 13console.log(calcHypotenuse(0, 0));// 予想される結果: 0

構文

js
Math.sqrt(x)

引数

x

0 以上の数値です。

返値

x の平方根です。x < 0 の場合、NaN を返します。

解説

sqrt()Math の静的メソッドであるため、生成したMath オブジェクトのメソッドとしてではなく、常にMath.sqrt() として使用するようにしてください (Math はコンストラクターではありません)。

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

仕様書

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

ブラウザーの互換性

関連情報

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp