Skip to content

Files

Latest commit

 

History

History
21 lines (15 loc) · 525 Bytes

prefer-modern-math-apis.md

File metadata and controls

21 lines (15 loc) · 525 Bytes

Pattern: Legacy mathematical operation patterns

Issue: -

Description

Modern JavaScript provides more concise and readable alternatives to legacy mathematical operations. For example, Math.log10(x) should be used instead of Math.log(x) * Math.LOG10E, and Math.hypot(a, b) is preferred over Math.sqrt(a * a + b * b).

Examples

Example of incorrect code:

Math.log(x) * Math.LOG10E;
Math.sqrt(a * a + b * b);

Example of correct code:

Math.log10(x);
Math.hypot(a, b);