MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Comparison Operators0%
Study Materials
JavaScript for BeginnersProgress 0%
1.1What is JavaScript?1.2How JavaScript Works in Browser1.3Setting up Environment: VSCode, Live Server
3.1Arithmetic Operators3.2Comparison Operators3.3Logical Operators3.4Assignment & Ternary Operator
HomeTutorialsJavaScript for BeginnersComparison Operators
Logical Operators

Comparison Operators

Beginner12 min read•Updated: 2026-09-15•By Er. Sumit Kumar (MSK Institute)
Study Materials

Comparison operators test the relationship between two values and return a Boolean (true or false). Master the difference between loose equality (==) and strict equality (===) to eliminate subtle bugs.


1. Overview of Comparison Operators

OperatorMeaningExampleResult
===Strict Equality (Same value AND same type)5 === 5true
!==Strict Inequality (Different value OR different type)5 !== "5"true
==Loose Equality (Type coerces before comparison)5 == "5"true (Caution!)
!=Loose Inequality (Type coerces before comparison)5 != "5"false
>Greater Than10 > 5true
<Less Than3 < 7true
>=Greater Than or Equal To10 >= 10true
<=Less Than or Equal To4 <= 9true

2. Strict Equality (===) vs. Loose Equality (==)

The Trap of Loose Equality (==):

When using ==, JavaScript uses complex implicit type conversion (coercion) before comparing:

1console.log(5 == "5"); // true (String "5" converted to number 5)
2console.log(0 == false); // true (false converted to 0)
3console.log("" == false); // true (empty string converted to 0)
4console.log(null == undefined);// true (special specification rule)
5console.log([] == 0); // true (empty array coerced to empty string, then 0!)

The Safety of Strict Equality (===):

Strict equality never coerces types. If the types differ, it immediately returns false:

1console.log(5 === "5"); // false (Number vs String)
2console.log(0 === false); // false (Number vs Boolean)
3console.log("" === false); // false (String vs Boolean)
4console.log(null === undefined);// false (Null vs Undefined)
[!IMPORTANT] Universal Professional Rule: ALWAYS use === and !==. Never use == or !=. Every reputable company linter (ESLint, Airbnb, Google) enforces this rule strictly.

3. Relational Comparisons with Strings

When comparing strings using >, <, >=, <=, JavaScript compares character codes alphabetically (lexicographically) using their ASCII/Unicode numerical values:

1console.log("b" > "a"); // true (Unicode 98 > 97)
2console.log("apple" < "banana"); // true ('a' comes before 'b')
3console.log("10" < "2"); // true! (Lexicographically, '1' comes before '2'!)
Important Warning
[!WARNING] Always parse strings to numbers with Number() or parseInt() before performing mathematical range comparisons!

4. Comparing Objects and Arrays

Remember: Objects and Arrays are compared by memory reference, NOT by internal contents!

1const listA = [1, 2, 3];
2const listB = [1, 2, 3];
3 
4console.log(listA === listB); // false! (They reside at different memory addresses in heap!)
5 
6const listC = listA;
7console.log(listA === listC); // true! (They share the exact same memory reference!)

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
What does strict equality (===) check in JavaScript?
Question 2
What is the result of 0 == false vs 0 === false?
Question 3
Why does [10] === [10] evaluate to false?
Question 4
Which operator checks whether value $A$ is NOT strictly equal to value $B$?
Question 5
What is the output of "100" > "20"?
Next Lesson

Logical Operators

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Arithmetic OperatorsLogical Operators

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master JavaScript for Beginners with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext