Related Topics

JAVASCRIPT
Arithmetic operators are used to perform mathematical operations on numbers. For example, the following code adds 10 to the variable
num
and assigns the result to the variablesum
:
Comparison operators are used to compare two values and determine if they are equal, greater than, less than, etc. For example, the following code compares the values of the variables
num1
andnum2
and determines if they are equal:
Logical operators are used to combine two or more logical expressions. For example, the following code uses the
&&
operator to combine two logical expressions and determine if both expressions are true:
Bitwise operators are used to perform bitwise operations on numbers. For example, the following code performs a bitwise AND operation on the numbers 10 and 20 and assigns the result to the variable
result
:
Ternary operators are used to evaluate a condition and return one of two values depending on the outcome. For example, the following code uses the ternary operator to evaluate the condition
num > 10
and return the value oftrue
if the condition is true, or the value offalse
if the condition is false:
Other operators include operators such as the
typeof
operator, which is used to determine the type of a value, and theinstanceof
operator, which is used to determine if a value is an instance of a particular object.
Here are some examples of unary, binary, and ternary operators in JavaScript:
Subtraction: The
-
operator subtracts the second operand from the first operand. For example, the following code subtracts 20 from 10 and assigns the result to the variabledifference
:
Multiplication: The
*
operator multiplies two operands together. For example, the following code multiplies 10 and 20 together and assigns the result to the variableproduct
:
Division: The
/
operator divides the first operand by the second operand. For example, the following code divides 100 by 20 and assigns the result to the variablequotient
:
Modulo: The
%
operator returns the remainder of a division operation. For example, the following code divides 100 by 20 and returns the remainder, which is 0:
These are just a few examples of arithmetic operators in JavaScript. There are many other arithmetic operators available, such as the ++
and --
operators, which are used to increment and decrement variables, respectively.
The conditional operator can be used to write more concise and readable code. However, it is important to use the conditional operator sparingly, as it can make code more difficult to understand.
Here are some other examples of the conditional operator in JavaScript:
For example, the following code uses the conditional operator to check if the value of the variable num
is greater than 10. If the value of num
is greater than 10, the value "greater than 10"
is returned. Otherwise, the value "less than or equal to 10"
is returned.
The conditional operator can be used to write more concise and readable code. However, it is important to use the conditional operator sparingly, as it can make code more difficult to understand.
Here are some other examples of the conditional operator in JavaScript:
The ||
operator returns true if either of its operands is true. If both operands are false, the ||
operator returns false.
For example, the following code returns true because one of the operands is true:
The !
operator negates the value of its operand. If the operand is true, the !
operator returns false. If the operand is false, the !
operator returns true.
For example, the following code returns true because the operand is false:
Logical operators can be used to combine logical expressions in a variety of ways. For example, the following code returns true if the value of num
is greater than 5 and less than 10:
Logical operators can also be used to check for the absence of a value. For example, the following code returns true if the variable num
is undefined:




Popular Category
Topics for You
Go through our study material. Your Job is awaiting.