JS: Math (namespace)

By Xah Lee. Date: . Last updated: .

What is the Keyword β€œMath”

Math is the value of the property key "Math" of the Global Object .

console.assert(globalThis["Math"] === Math);

Type

Type of Math is Object .

console.assert(typeof Math === "object");

Parent

Parent of Math is Object.prototype.

console.assert(Reflect.getPrototypeOf(Math) === Object.prototype);

Purpose

Purpose of Math object is as a namespace for math related functions and constants.

Properties

Misc

Math.hypot(x1, x2, etc)

(new in ECMAScript 2015)

Return the square root of (x1^2 + x2^2 + etc^2). This is useful to compute the length of a higher dimension vector in linear algebra.

// length of 2d unit vector
console.log(Math.hypot(1, 1));
// 1.4142135623730951

// length of 3d unit vector
console.log(Math.hypot(1, 1, 1));
// 1.7320508075688772

Math[Symbol.toStringTag]

(new in ECMAScript 2015)

value is the string "Math".

JavaScript. math functions.

JavaScript. Number