In JavaScript, the way operators are applied depends on their precedence. Multiplication and division take precedence over addition and subtraction .
Here are some advanced math operators that you can use while writing programs:
Modulo operator (%):
This operator returns the remainder of a division operation. For example:
Exponentiation operator (--):
This operator raises a number to the power of another number. It's a newer operator and may not be supported in all browsers, so you may need to use the Math.pow function instead. For example:
Increment operator (++):
This operator increases a number by one. It can be used as a prefix (before the operand) or a postfix (after the operand). For example:
Decrement operator (--):
This operator decreases a number by one. It can be used as a prefix (before the operand) or a postfix (after the operand). For example:
Math object:
The Math object in JavaScript provides mathematical functions and constants. You can use its methods for advanced math operations like finding square roots, calculating sines, or generating random numbers. For example:
These are just a few examples of the advanced math operators and functions available in JavaScript. There are many more you can use for complex math operations in your programs.
Understanding the Nullish Coalescing Operator '??'
The nullish coalescing operator returns the first argument if it's not null or undefined; otherwise, it returns the second one. It's written as two question marks The result of is:
If is defined, then .
If isn’t defined, then .