Back to Course

Introduction to JavaScript

0% Complete
0/0 Steps
  1. JavaScript: Basics
    9Topics
    |
    10 Quizzes
  2. JavaScript: Variables
    9Topics
    |
    10 Quizzes
  3. JavaScript: Conditional Statements
    10Topics
    |
    11 Quizzes
  4. JavaScript: Functions
    10Topics
    |
    11 Quizzes
  5. JavaScript: Scope
    6Topics
    |
    7 Quizzes
  6. JavaScript: Arrays
    11Topics
    |
    12 Quizzes
  7. JavaScript: Loops
    8Topics
    |
    9 Quizzes
  8. JavaScript: High Order Functions
    3Topics
    |
    4 Quizzes
  9. JavaScript: Iterators
    3Topics
    |
    3 Quizzes
Lesson 3, Topic 5
In Progress

JavaScript: Comparison Operators

Yasin Cakal 31 Oct 2021
Lesson Progress
0% Complete

When writing conditional statements, we sometimes need to compare values using different types of operators. These are referred to as comparison operators.

Here are some useful comparison operators, along with their syntax:

  1. Less than: <
  2. Greater than: >
  3. Less than or equal to: <=
  4. Greater than or equal to: >=
  5. Is equal to: ===
  6. Is not equal to: !==

The values on the left and right are compared using comparison operators. Consider the following:

20<15 
//Evaluates to false.

Comparing statements might be helpful if thought of as questions. The statement evaluates true when the response is “yes,” and it evaluates false when the answer is “no.” Is 20 less than 15? would be the question raised by the code above. No! As a result, 20 <15 evaluates to false.

We can perform a comparison among values of other data types too. Let’s take an example of string data type:

'java' === 'javascript' // false

We’re using the identity operator === to see if the string java is the same as the string javascript in the example above. The comparison expression evaluates to false since the two strings are not the same.

All comparison statements are made up of two values that will be compared and evaluated to true or false. The two things are as follows:

  • Two values on which the comparison would be carried out .
  • An operator that separates the values and compares them accordingly (><<=,>=,===,!==).

Responses

Leave a Reply

%d bloggers like this: