-
Hajipur, Bihar, 844101
Hajipur, Bihar, 844101
JS Basics
JS Variables & Operators
JS Data Types & Conversion
JS Numbers & Math
JS Strings
JS Dates
JS Arrays
JS Control Flow
JS Loops & Iteration
JS Functions
JS Functions
Function Definitions
Function Parameters
Function Invocation
Function Call
Function Apply
Function Bind
Function Closures
JS Arrow Function
JS Objects
JS Objects
JS Object Properties
JS Object Methods
JS Object Display
JS Object Constructors
Object Definitions
Object Get / Set
Object Prototypes
Object Protection
JS Classes & Modules
JS Async Programming
JS Advanced
JS Destructuring
JS Bitwise
JS RegExp
JS Precedence
JS Errors
JS Scope
JS Hoisting
JS Strict Mode
JS this Keyword
JS HTML DOM
DOM Intro
DOM Methods
DOM Document
DOM Elements
DOM HTML
DOM Forms
DOM CSS
DOM Animations
DOM Events
DOM Event Listener
DOM Navigation
DOM Nodes
DOM Collections
DOM Node Lists
JS BOM (Browser Object Model)
JS Window
JS Screen
JS Location
JS History
JS Navigator
JS Popup Alert
JS Timing
JS Cookies
Web Storage API
JS Web APIs
JS AJAX
AJAX Intro
AJAX XMLHttp
AJAX Request
AJAX Response
AJAX XML File
AJAX PHP
AJAX ASP
AJAX Database
AJAX Applications
AJAX Examples
JS JSON
JSON Intro
JSON Syntax
JSON vs XML
JSON Data Types
JSON Parse
JSON Stringify
JSON Objects
JSON Arrays
JSON Server
JSON PHP
JSON HTML
JSON JSONP
JS Canvas
JS Graphics & Charts
JS Basics
JS Variables & Operators
JS Data Types & Conversion
JS Numbers & Math
JS Strings
JS Dates
JS Arrays
JS Control Flow
JS Loops & Iteration
JS Functions
JS Functions
Function Definitions
Function Parameters
Function Invocation
Function Call
Function Apply
Function Bind
Function Closures
JS Arrow Function
JS Objects
JS Objects
JS Object Properties
JS Object Methods
JS Object Display
JS Object Constructors
Object Definitions
Object Get / Set
Object Prototypes
Object Protection
JS Classes & Modules
JS Async Programming
JS Advanced
JS Destructuring
JS Bitwise
JS RegExp
JS Precedence
JS Errors
JS Scope
JS Hoisting
JS Strict Mode
JS this Keyword
JS HTML DOM
DOM Intro
DOM Methods
DOM Document
DOM Elements
DOM HTML
DOM Forms
DOM CSS
DOM Animations
DOM Events
DOM Event Listener
DOM Navigation
DOM Nodes
DOM Collections
DOM Node Lists
JS BOM (Browser Object Model)
JS Window
JS Screen
JS Location
JS History
JS Navigator
JS Popup Alert
JS Timing
JS Cookies
Web Storage API
JS Web APIs
JS AJAX
AJAX Intro
AJAX XMLHttp
AJAX Request
AJAX Response
AJAX XML File
AJAX PHP
AJAX ASP
AJAX Database
AJAX Applications
AJAX Examples
JS JSON
JSON Intro
JSON Syntax
JSON vs XML
JSON Data Types
JSON Parse
JSON Stringify
JSON Objects
JSON Arrays
JSON Server
JSON PHP
JSON HTML
JSON JSONP
JS Canvas
JS Graphics & Charts
Comparison operators in JavaScript allow you to compare two values and return a Boolean: true
or false
.
They are widely used in:
if
statements
while
/for
loops
Filtering data
Conditional rendering, etc.
Operator | Meaning | Example |
---|---|---|
== |
Equal to (loose) | 5 == "5" → true |
=== |
Strictly equal to (type+value) | 5 === "5" → false |
!= |
Not equal to (loose) | 5 != "5" → false |
!== |
Strictly not equal (type+val) | 5 !== "5" → true |
> |
Greater than | 10 > 5 → true |
< |
Less than | 3 < 7 → true |
>= |
Greater than or equal | 8 >= 8 → true |
<= |
Less than or equal | 4 <= 3 → false |
==
vs ===
5 == "5"; // true (type coercion)
5 === "5"; // false (strict comparison)
✅ Use ===
for safer, more predictable comparisons.
Every comparison returns true
or false
:
let a = 10;
let b = 20;
console.log(a > b); // false
console.log(a <= b); // true
console.log("apple" < "banana"); // true
🔤 Alphabetical comparison is based on UTF-16 character code order.
JavaScript may convert types automatically in loose comparisons:
0 == false; // true
0 === false; // false
"5" == 5; // true
null == undefined; // true
null === undefined; // false
[] == false; // true
{} == false; // false
[] == []; // false (different references)
⚠️ Comparing objects/arrays with ==
or ===
compares references, not content.
Q1. What is the difference between ==
and ===
in JavaScript?
Q2. How do you compare whether two values are not equal and of different types?
Q3. What will 0 == false
return and why?
Q4. How can you compare two numbers and check if one is greater or equal to the other?
Q5. Which operator would you use to check strict inequality?
Q6. How does JavaScript compare strings using <
or >
operators?
Q7. What is the result of "5" == 5
and why?
Q8. How do you compare whether a value is less than or equal to another in an if
condition?
Q9. What happens when you compare two arrays like [1,2] === [1,2]
?
Q10. Why is it recommended to use ===
over ==
in most cases?
Q1: What is the output of 5 == '5'?
Q2: Which operator checks both value and type?
Q3: What is the result of null == undefined?
Q4: Which operator represents strict inequality?
Q5: What will "abc" < "bcd" return?
Q6: What is the output of 0 === false?
Q7: What does >= mean?
Q8: Which comparison returns false?
Q9: What is the result of [] == false?
Q10: What is the result of comparing NaN == NaN?