Goseeko blog

What is a Javascript operator?

by Bhumika

JavaScript allows you to use the following operators :

Arithmetic operator 

For example, Assume that variable A is equal to 10 and variable B is equal to 20.

  • + (Addition) –  Add two operands
  • – (Subtraction) – The second operand is subtracted from the first.
  • * (Multiplication) – Multiply both operands
  • / (Division) – Divide the denominator from the numerator.
  • % (Modulus) – The remainder of an integer division is returned.
  • ++ (Increment) – Increases an integer value by one
  • — (Decrement) – Decreases an integer value by one

Comparison operator 

Assume variable A has a value of 10 and variable B has a value of 20.

  • = = (Equal) – Checks whether the values of two operands are equal; if they are, the condition is true.
  • != (Not Equal) – Checks whether the values of two operands are equal or not; if they aren’t, the condition is false.
  • > (Greater than) – Checks whether the left operand’s value is greater than the right operand’s value; if it is, the condition is true.
  • < (Less than) – Checks if the left operand’s value is less than the right operand’s value; if it is, the condition is true.
  • >= (Greater than or Equal to) – Checks whether the left operand’s value is larger than or equal to the right operand’s value; if it is, the condition is true.
  • > (Right Shift) – Right Shift Operator in Binary. In addition, the value of the left operand is shift right to the number of bits indicated by the right operand.

Assignment operators

The following assignment operators are support by JavaScript

  • = (Simple Assignment ) – Values from the right side operand are transfer to the left side operand.
  • += (Add and Assignment) – The right operand is added to the left operand, and the result is assign to the left operand.
  • −= (Subtract and Assignment) – The right operand is subtracted from the left operand, and the result is assign to the left operand.
  • *= (Multiply and Assignment) – It adds the right and left operands together and assigns the result to the left operand.
  • /= (Divide and Assignment) – The left operand is divide the right operand, and the result is assign to the left operand.
  • %= (Modules and Assignment) – It uses two operands to calculate modulus and assigns the result to the left operand.

Interested in learning about similar topics? Here are a few hand-picked blogs for you!

You may also like