Operators

An operator is a special character or series of characters that perform a task in JavaScript.

Assignment Operator

The assignment operator (=) assigns a value to a variable.

var x = 10;

Arithmetic Operators

Arithmetic operators are used to perform arithmetic on numbers:

  • + addition
  • - subtraction
  • * multiplication
  • / division
  • % modulo
// Addition
5 + 5;
// Subtraction
10 - 5;
// Multiplication
5 * 10;
// Division
10 / 5;
// Modulo
10 % 5;

Assignment Operators

An assignment operator assigns a value to its left operand based on the value of its right operand. Here are some of them:

  • += addition assignment
  • -= subtraction assignment
  • *= multiplication assignment
  • /= division assignment
let number = 100;
// Both statements will add 10
number = number + 10;
number += 10;
console.log(number);
// Output: 120

Comparison Operators

  • == equal to
  • === equal value and equal type
  • != not equal
  • !== not equal value or not equal type
  • > greater than
  • < less than
  • >= greater than or equal to
  • <= less than or equal to
  • ? ternary operator
Edit this page on GitHub

Contributors

Interested in helping build Docs? Read the Contribution Guide or share your feedback form.

Learn JavaScript on Codecademy

Edit this page on GitHub

Contributors