Convert a string into an integer (a whole number).
Math Related
Take a number and return it in the specified currency formatting
Use Intl.NumberFormat to enable country / currency sensitive formatting.
The Exponent Operator
Do you useMath.pow() to raise a number to a power? Did you know you can use the exponent operator ** as well?
Calculate the midpoint between two pairs of (x,y) points
Destructure the array to get x1, y1, x2 and y2. Calculate the midpoint for each dimension by dividing the sum of the two endpoints by 2.
Round a number to a specified amount of digits
Use Math.round() and template literals to round the number to the specified number of digits. Omit the second argument, decimals, to round to an integer.
Check if the given value is a number
Use parseFloat() to try to convert n to a number. Use !Number.isNaN() to check if num is a number.
Generating random numbers with JavaScript
In this snippet, look at how to get a random integer between two numbers.
Check if the given number is even
Check whether a number is odd or even using the modulo (%) operator. Return true if the number is even, false if the number is odd.
Check if the given number is odd
Check whether a number is odd or even using the modulo (%) operator. Return true if the number is odd, false if the number is even.
Calculate the nth root of a given number
Use Math.pow() to calculate x to the power of 1/n which is equal to the nth root of x.