Video Lesson

Lesson Notes

Using Greater Than and Less Than Operators in JavaScript

In this video, I explain how to use the greater than (>) and less than (<) operators in JavaScript. These operators allow you to compare numerical values and write conditional logic based on the results.

Example with Hardcoded Values

1if (1 > 0) { 2 console.log("Hello world"); 3}
  • This logs "Hello world" because 1 is greater than 0.

Using a Variable for Comparison

Let’s make it more dynamic by using a variable:

1const fu = 1; 2 3if (fu > 0) { 4 console.log("fu is bigger than 0"); 5} else if (fu < 0) { 6 console.log("fu is less than 0"); 7}

Testing with a Negative Value

Change the value of fu to test the other branch:

1const fu = -1;
  • Now the output will be "fu is less than 0".

Summary

  • Use > to check if a number is greater than another.
  • Use < to check if a number is less than another.
  • Combine these with if, else if, and else for control flow in your programs.

These comparison operators are essential when building logic for games, apps, or any interactive system.

AI Assistant

Sign In Required

Sign in and subscribe to use the AI assistant for instant help with your lessons.

Sign In

Greater Than and Less Than in JavaScript

In this video, I cover how to use the greater than (>) and less than (<) operators in JavaScript. You'll learn how to compare numbers using conditional statements and control your program’s flow based on numeric values. A simple but essential part of writing logic in JavaScript.

1m 29s

Course Content

0 of 32 lessons completed
6. Promises, Async and Await
0 of 0 completed
7. The DOM
0 of 0 completed