1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[JavaScript][Object Methods] Mathオブジェクトのメソッドとは

Last updated at Posted at 2025-09-10

概要

Math オブジェクトは、JavaScript において 数学的な定数や関数を提供するビルトインオブジェクト(組み込みオブジェクト) です。
Array.map() のようにインスタンスから呼び出すのではなく、Math という単体のオブジェクトに属するメソッドとしてMath.メソッド名() の形式で直接呼び出します。
※参考:MDN Web Docs – Math

つまり、Mathnew でインスタンス化できない特殊なオブジェクトであり、
数学計算のための「名前空間(namespace)」として機能します。

目次

基本構文

Math のメソッドは、インスタンスを生成せずに直接呼び出すことができます。

Math.メソッド名(引数);

例:

console.log(Math.sqrt(16));  // 4
console.log(Math.pow(2, 3)); // 8

代表的なメソッド

Math.min

数値の中から 最小値を返すメソッド。

console.log(Math.min(3, 7, -2, 8));
// 出力結果: -2

配列から最小値を求める場合は スプレッド構文 を使用します。

const numbers = [19, 5, 42, 2, 77];
console.log(Math.min(...numbers));
// 出力結果: 2

Math.max

数値の中から 最大値を返すメソッド。

console.log(Math.max(3, 7, -2, 8));
// 出力結果: 8

配列でも同様に使えます。

const numbers = [19, 5, 42, 2, 77];
console.log(Math.max(...numbers));
// 出力結果: 77

Math.sqrt

平方根(√)を返すメソッド。

console.log(Math.sqrt(25)); // 5
console.log(Math.sqrt(2));  // 1.4142135623730951

Math.pow

累乗(べき乗)を計算するメソッド。

console.log(Math.pow(2, 3)); // 8 (2の3乗)
console.log(Math.pow(5, 2)); // 25 (5の2乗)

ES2016 以降は 累乗演算子(** が推奨です。

console.log(2 ** 3); // 8

活用例

配列から 最小値と最大値の差の平方根 を求める例。

const numbers = [10, 25, 4, 64, 32];

const min = Math.min(...numbers);  // 4
const max = Math.max(...numbers);  // 64

const result = Math.sqrt(max - min);
console.log(result); // 7.483314773547883

参考リンク

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?