Home HTML CSS JavaScript React Gamedatum.com
× Home HTML CSS JavaScript React Gamedatum.com

JS Operators


What's a JavaScript Operator?

The JavaScript Operator is a symbol which performs an operation for a value or a set of values or data.

Below are the types of JavaScript Operators:

  • Assignment Operators
  • Comparison Operators
  • Arithmetic Operators
  • Logical Operators
  • Conditional Operators

Assignment Operators

The assignment operator is the basic = symbol.

e.g. let x = 3;

Comparison Operators

The comparison operators are:

> (greater than),
< (less than),
= (equal to),
!= (not equal to),
<= (less than or equal to),
>= (greater than or eaual to),
== (strictly equal to)

Arithmetic Operators

  • + Add
  • * Multiply
  • - Sutract
  • ** Expenential
  • % Modulus
  • -- Decrement
  • ++ Increment
  • / Divide

Logical Operators

The Logical Operators are:

|| (OR), && (AND), ! (NOT)

Example:

               
                
<script>
// || (OR)
x = "a";
y = 5;

if (x = "a" || y < 1) {
  //display some message
}
// && (AND)
if (x = "a" && y = 5) {
 //display some message
}
// ! (NOT)
if (x != "b" ) {
 //display some message
}


</script>
                
                
              

Conditional Operators

The JavaScript conditionals: if, else, and else if

               
                
<script>
// || (OR)
x = "a";
y = 5;

if (x = "a") {
  //display some message
} else {
  //display another message
}

if (x = "a") {
  //display some message
} else if (x = "a" && y = 5){
  //display another message
} else {
  //display another message
}



</script>