ES2015 introduced several new Math methods that simplify common mathematical operations.
Using these modern methods improves code readability and intent.
This rule flags legacy patterns that can be replaced with:
Math.log10(): Calculates the base-10 logarithm
Math.log2(): Calculates the base-2 logarithm
Math.hypot(): Calculates the Euclidean distance (square root of sum of squares)
An intrinsic object that provides basic mathematics functionality and constants.
Math.
Math.log(x: number): number
Returns the natural logarithm (base e) of a number.
@param ― x A numeric expression.
log(
const x:number
x) *
var Math:Math
An intrinsic object that provides basic mathematics functionality and constants.
Math.
Math.LOG10E: number
The base-10 logarithm of e.
LOG10E;
const
const log10Value:number
log10Value =
var Math:Math
An intrinsic object that provides basic mathematics functionality and constants.
Math.
Math.log(x: number): number
Returns the natural logarithm (base e) of a number.
@param ― x A numeric expression.
log(
const x:number
x) /
var Math:Math
An intrinsic object that provides basic mathematics functionality and constants.
Math.
Math.LN10: number
The natural logarithm of 10.
LN10;
const
const log2Value:number
log2Value =
var Math:Math
An intrinsic object that provides basic mathematics functionality and constants.
Math.
Math.log(x: number): number
Returns the natural logarithm (base e) of a number.
@param ― x A numeric expression.
log(
const x:number
x) *
var Math:Math
An intrinsic object that provides basic mathematics functionality and constants.
Math.
Math.LOG2E: number
The base-2 logarithm of e.
LOG2E;
const
const log2Value:number
log2Value =
var Math:Math
An intrinsic object that provides basic mathematics functionality and constants.
Math.
Math.log(x: number): number
Returns the natural logarithm (base e) of a number.
@param ― x A numeric expression.
log(
const x:number
x) /
var Math:Math
An intrinsic object that provides basic mathematics functionality and constants.
Math.
Math.LN2: number
The natural logarithm of 2.
LN2;
const
const absolute:number
absolute =
var Math:Math
An intrinsic object that provides basic mathematics functionality and constants.
Math.
Math.sqrt(x: number): number
Returns the square root of a number.
@param ― x A numeric expression.
sqrt(
const x:number
x ** 2);
const
const distance:number
distance =
var Math:Math
An intrinsic object that provides basic mathematics functionality and constants.
Math.
Math.sqrt(x: number): number
Returns the square root of a number.
@param ― x A numeric expression.
sqrt(
const x:number
x ** 2 +
const y:number
y ** 2);
const
const log10Value:number
log10Value =
var Math:Math
An intrinsic object that provides basic mathematics functionality and constants.
Math.
Math.log10(x: number): number
Returns the base 10 logarithm of a number.
@param ― x A numeric expression.
log10(
const x:number
x);
const
const log2Value:number
log2Value =
var Math:Math
An intrinsic object that provides basic mathematics functionality and constants.
Math.
Math.log2(x: number): number
Returns the base 2 logarithm of a number.
@param ― x A numeric expression.
log2(
const x:number
x);
const
const absolute:number
absolute =
var Math:Math
An intrinsic object that provides basic mathematics functionality and constants.
Math.
Math.abs(x: number): number
Returns the absolute value of a number (the value without regard to whether it is positive or negative).
For example, the absolute value of -5 is the same as the absolute value of 5.
@param ― x A numeric expression for which the absolute value is needed.
abs(
const x:number
x);
const
const distance:number
distance =
var Math:Math
An intrinsic object that provides basic mathematics functionality and constants.
Math.
Math.hypot(...values: number[]): number
Returns the square root of the sum of squares of its arguments.
@param ― values Values to compute the square root for.
If no arguments are passed, the result is +0.
If there is only one argument, the result is the absolute value.
If any argument is +Infinity or -Infinity, the result is +Infinity.
If any argument is NaN, the result is NaN.
If all arguments are either +0 or −0, the result is +0.