Math.SQRT2

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.

Math.SQRT2 プロパティは、 2 の平方根、約 1.414 を表します。

試してみましょう

function getRoot2() {
  return Math.SQRT2;
}

console.log(getRoot2());
// Expected output: 1.4142135623730951

𝙼𝚊𝚝𝚑.𝚂𝚀𝚁𝚃𝟸=21.414\mathtt{Math.SQRT2} = \sqrt{2} \approx 1.414
Math.SQRT2 のプロパティ属性
書込可能不可
列挙可能不可
設定可能不可

解説

Math.SQRT2 は定数であり、 Math.sqrt(2) と同等でよりパフォーマンスの高いものです。

SQRT2Math オブジェクトの静的プロパティなので、 Math オブジェクトを生成してプロパティとして使用するのではなく、常に Math.SQRT2 として使用するようにしてください (Math はコンストラクターではありません)。

Math.SQRT2 の使用

以下の関数は 2 の平方根を返します。

js
function getRoot2() {
  return Math.SQRT2;
}

getRoot2(); // 1.4142135623730951

仕様書

Specification
ECMAScript® 2025 Language Specification
# sec-math.sqrt2

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
SQRT2

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

関連情報