👨‍💻
Learn to Code
  • Welcome
  • HTML
    • The Basics
    • Getting Started
  • JavaScript
    • The Basics
      • Values
      • Variables
      • Functions
      • Operators
      • Conditional Statements
      • Arrays
      • Loops
    • Intro to the DOM
    • Working with the DOM
    • Activities
      • Text Summariser
        • Getting the words
        • Ranking the sentences
        • Getting the summary
      • Greeter Function
      • Fizz Buzz
      • Temperature Converter
Powered by GitBook
On this page
  • Math Operators
  • Comparison Operators

Was this helpful?

  1. JavaScript
  2. The Basics

Operators

Operators are a type of construct which represents an action or relationship. We can use them to compare and modify values. You are already familiar with some of the more common operators, such as the ones commonly used in mathematical expressions.

Math Operators

  • + Addition

  • - Subtraction

  • * Multiplication

  • / Division

  • % Remainder

  • ** Exponent

These work largely the same as their math counterparts, and can be used to combine values into new values resulting from the expressions you write.

var sumOfNumbers = 1 + 3;
alert(sumOfNumbers);

Comparison Operators

While the previous operators are used to create and modify values, these ones are used to compare values. The most common ones are:

  • == Equal to

  • === Identical to

  • > Greater than

  • < Less than

  • >= Greater than or equal to

  • <= Less than or equal to

There is an important distinction between == and === which is that the "equal to" operator essentially only compares that two values are equivalent, while the "identical to" operator checks that the identity of the values is also the same. What this means is that the "identical to" operator also checks the type of the variable.

Because of this, the following occurs:

"1" == 1; // true . This is true because the values are equivalent when not considering the types

"1" === 1; //false . This is false, because even though the values are equivalent, they are different types (string vs number) so they are not identical

PreviousFunctionsNextConditional Statements

Last updated 5 years ago

Was this helpful?