JavaScript provides several bitwise operators that allow you to manipulate the individual bits within a value. These operators include: Here’s a brief explanation of each operator and an example of how to use it: Bitwise AND (&) The bitwise AND operator compares each bit of the first operand to the corresponding bit of the second […]
Assignment Operators in JavaScript
JavaScript has several assignment operators that can be used to assign values to variables. These operators are as follows: The “=” operator: This is the most basic assignment operator and is used to assign a value to a variable. For example: The “+=” operator: This operator is used to add the value on the right […]
The JavaScript function Math.pow()
The Math.pow() function in JavaScript is used to raise a number (called the base) to a certain power (called the exponent). The syntax for using this function is Math.pow(base, exponent). For example, to raise 2 to the power of 3, you would use the following code: In this example, 2 is the base and 3 […]
The JavaScript function Math.floor()
The JavaScript function Math.floor() is used to round a number down to the nearest integer. This function takes a single argument, which is the number that you want to round down. For example, if you wanted to round the number 4.7 down to the nearest integer, you would use the following code: As you can […]
The JavaScript function Math.abs()
The JavaScript function Math.abs() is a built-in function that returns the absolute value of a number. The absolute value of a number is its distance from zero, regardless of whether the number is positive or negative. Here is an example of how to use the Math.abs() function: In the above example, num1 is assigned the […]
Arithmetic Operators in JavaScript
JavaScript has several arithmetic operators that are used to perform mathematical operations on numbers. These operators include: Addition (+): This operator is used to add two or more numbers together. Subtraction (-): This operator is used to subtract one number from another. Multiplication (*): This operator is used to multiply two or more numbers together. […]
Viewport Width
There are two methods to get the viewport width: window.innerWidth and document.documentElement.clientWidth. The former is more accurate. The latter has better browser support. To get the best of both worlds, try innerWidth first, and fallback to clientWidth if not supported. Source https://vanillajstoolkit.com/reference/viewport/viewport-width/
Using the spread operator
The spread operator allows you to quite literally “spread” out an array. This can be used to transform an array into a list of arguments or even combine two arrays together. You could also use it to form a list of arguments to a function too. Check it out: In the first example we show […]
Drop list elements from the left
Creates a new array with n elements removed from the left. Source https://www.30secondsofcode.org/js/s/drop
Get the height of the viewport
There are two methods to get the viewport height: window.innerHeight and document.documentElement.clientHeight. The former is more accurate. The latter has better browser support. To get the best of both worlds, try innerHeight first, and fallback to clientHeight if not supported. Source https://vanillajstoolkit.com/reference/viewport/viewport-height/