Hassib Moddasser
Hassib Moddasser

@hassibmoddasser

16 تغريدة 27 قراءة May 27, 2022
11 Math Functions in JavaScript that you must know, plus the cheatsheet
{ thread }
Hi, my name is Hassib; I'm a Software Engineer and a freelance web developer with 4+ years of experience.
In this series of tweets, I want to show you the commonly used Math functions that every JavaScript developer should know.
Let's dive in and have fun!
Introduction
Math is a built-in object that provides properties and methods for mathematical constants and functions to execute mathematical operations.
Unlike many other global objects, the Math object has no constructor.
{ 1 / 13 }
Cont.
All properties and methods of the Math object are static, and it works with the Number type. It doesn't work with BigInt.
Following is a list of commonly used Math object methods:
{ 2 / 13 }
1⃣ Math.abs
The "Math.abs" function returns the absolute value of a number. It takes a number as its parameter and returns its absolute value.
{ 3 / 13 }
2⃣ Math.ceil
The Math.ceil function always rounds a number up to the next largest integer. It takes a number as its parameter and returns its upward round value.
{ 4 / 13 }
3⃣ Math.floor
The Math.floor function rounds a number down to its nearest integer. It takes a number as its parameter and returns its downward round value.
{ 5 / 13 }
4⃣ Math.round
The Math.round function rounds a number to its nearest integer. It takes a number as its parameter and returns its nearest rounded value.
{ 6 / 13 }
5⃣ Math.trunc
The Math.trunc function takes a number as its parameter and returns its integer part of a number by removing any fractional digits.
{ 7 / 13 }
6⃣ Math.max
The Math.max function returns the largest of 0 to n numbers given as input parameters.
{ 8 / 13 }
7⃣ Math.min
The Math.min function returns the smallest of 0 to n numbers given as input parameters.
{ 9 / 13 }
8⃣ Math.pow
The Math.pow function returns the base to the exponent power. It takes two number parameters and returns as base^exponent.
{ 10 / 13 }
9⃣ Math.sqrt
The Math.sqrt function takes a number as a parameter and returns the square root of the number.
{ 11 / 13 }
1⃣0⃣ Math.cbrt
The Math.cbrt function returns the cube root of a number taken as a parameter.
{ 12 / 13 }
1⃣1⃣ Math.random
The Math.random function returns a floating-point, pseudo-random number in the range 0 to less than 1 (inclusive of 0, and exclusive of 1).
{ 13 / 13 }
The Math object allows you to perform mathematical instructions. It has 8 static properties and more than 30 static methods.
Here's the 10+ cheatsheet of JavaScript's Math functions as a bonus! 💛
Before you leave, follow me @hassibmoddasser and Retweet the first Tweet! 😇

جاري تحميل الاقتراحات...