JS: Math (namespace)

By Xah Lee. Date: . Last updated: .

What is the Keyword β€œMath”

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 vector (1,1)
console.log(Math.hypot(1, 1));
// 1.4142135623730951

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

Math[Symbol.toStringTag]

(new in ECMAScript 2015)

value is the string "Math".