An operator is used to perform task for one or more values into a single resultant output value.

// Assign values to variables and add them together:

var x = 5;         // assign the value 5 to x
var y = 2;         // assign the value 2 to y
var z = x + y;     // assign the value 7 to z (x + y)

JavaScript operators are classified as:

  • Arithmetic
  • Logical
  • Comparison
  • String

An operator operates on operand or operands. The combination of one or more operators is referred to as an expression.

Java Script Operators

JavaScript Arithmetic Operators

OperatorDescription
+Addition
Subtraction
*Multiplication
**Exponentiation
/Division
%Modulus (Division Remainder)
++Increment
Decrement

console.log(5 + 4); // Prints 9
console.log(7 - 1); // Prints 6
console.log(6 * 2); // Prints 12
console.log(15 / 3); // Prints 5

Note: console.log() the computer will evaluate the expression inside the parentheses and print that result to the console.

The remainder operator, sometimes called modulo, returns the number that remains after the right-hand number divides into the left-hand number as many times as it evenly can: 11 % 3 equals 2 because 3 fits into 11 three times, leaving 2 as the remainder.

Leave a Reply

Your email address will not be published. Required fields are marked *