JavaScript == VS ===
Key Takeaways
The video discusses the difference between double equals (==) and triple equals (===) equality operators in JavaScript, highlighting the importance of using triple equals to avoid type conversion issues.
Full Transcript
you need to stop using the double equal sign there is only one instance where the double equal sign should be used and I'll be covering that at the end of this video so let's get started with what you should use instead it may sound a bit melodramatic to say to stop using the equal sign but let me back up my reasoning behind it let's just console log out here an equal statement we're just going to say 1 equal equal 1 and if we say that you'll see that that's true and of course that's going to be true it doesn't matter if we use equal equal or the more preferred triple equals both of these are going to equate to true but let's say we were comparing one equal to the string 1 what is this going to do is this true is this false it should be false because a number is not equal to a string but as you can see it prints out true over here and that's because double equal signs takes the type of the object and converts it so that they're both the same so this number 1 and this string they're going to be both converted to be equal to a number so it'll check 1 and then convert the string to a number is equal to that number 1 but if we use triple equals and we say that you now see that we get false instead of true and that's because this string of 1 is not equal to this number 1 now you may be thinking that's not really a big deal but this can cause a lot of really interesting problems so let's just console that log out here we have 0 is equal to an empty string as we both know this is definitely not true there's no way that 0 could ever equal an empty string but if we save that you'll see that it's equal to true and that's because it's converting the types of these objects before it's acquainting them to each other but if we use triple equals and we save you see that's equal to false because it does not convert the types of the objects this gives us a lot of weird bugs especially when entering empty values or for example if we check the 0 equal to false that says true even though 0 is not false and if we use equal equals you'll see it'll give us false instead of true for this statement but as I mentioned at the beginning this video there is one use case where you do want to use double equals sum times and that's when you're comparing a null for different objects but say you have an object and you want to see if that object is null so we have null or going to equal equal that to null which is obviously true and it doesn't matter if we use triple equals that'll also be true but sometimes you're going to have a null object that will actually be undefined instead of null so instead of null here we'll have undefined and that's a very common use case where you'll have undefined instead of null and that's actually equal to false null does not triple equal undefined but it does double equal undefined null and undefined are both considered the same when using double equals to compare and this in my opinion is the only use case where double equals should be used instead of triple equals the same rule of using double equals versus triple equals also applies to the not equal operator so let's put one over here we're going to just put the string of one and let's say that those are not equal to each other as we know exclamation point equal stands for not equal and if we say that we're going to get false because it's converting the values types before it is checking equal but if we put an exclamation point followed by two equal signs it is not going to convert the type and we'll see that these are actually not equal to each other as we would expect because the number one is not equal to the string one and this solves all the same bugs that we talked about earlier with empty strings in 0 0 and false and Nolan I'm defined as you see if we put in an ol on one side and we've put an undefined on this side we're going to see that these are actually not equal to each other but if we used single equal it would actually say that they are equal to each other so I hope you guys enjoyed that quick video on the differences between double equals and triple equals and JavaScript and why you should almost always use triple equals over a double equals unless you're comparing null and undefined you guys did enjoy this video make sure you check out my other JavaScript related videos linked over here and subscribe to my channel for more videos just like this thank you guys very much for watching and have a good day
Original Description
Unlike many programming languages JavaScript has both a double equals (==) and a triple equals (===) equality operator. For the most part these two operators work exactly the same, but the double equals operator converts the types of the objects being compared to the same type. This sounds like a good thing at first, but it can cause some strange bugs to occur when comparing certain objects/types. Because of this the triple equals operator should almost always be used, except in the case of checking if an object is null or undefined.
== vs === Article: https://blog.webdevsimplified.com/2020-08/==-vs-===
Twitter:
https://twitter.com/DevSimplified
GitHub:
https://github.com/WebDevSimplified
CodePen:
https://codepen.io/WebDevSimplified
#JavaScript #WebDevelopment #Programming
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Web Dev Simplified · Web Dev Simplified · 48 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
▶
49
50
51
52
53
54
55
56
57
58
59
60
Introduction to Web Development || Setup || Part 1
Web Dev Simplified
Introduction to Web Development || Understanding the Web || Part 2
Web Dev Simplified
Introduction to HTML || Your First Web Page || Part 1
Web Dev Simplified
Introduction to HTML || Basic HTML Elements || Part 2
Web Dev Simplified
Introduction to HTML || Advanced HTML Elements || Part 3
Web Dev Simplified
Introduction to HTML || Links and Inputs || Part 4
Web Dev Simplified
Learn Git in 20 Minutes
Web Dev Simplified
5 Must Know Sites For Web Developers
Web Dev Simplified
10 Best Visual Studio Code Extensions
Web Dev Simplified
Learn CSS in 20 Minutes
Web Dev Simplified
How to Style a Modern Website (Part One)
Web Dev Simplified
How to Style a Modern Website (Part Two)
Web Dev Simplified
3D Flip Button Tutorial
Web Dev Simplified
How to Style a Modern Website (Part Three)
Web Dev Simplified
Animated Loading Spinner Tutorial
Web Dev Simplified
How to Write the Perfect Developer Resume
Web Dev Simplified
Animated Text Reveal Tutorial
Web Dev Simplified
Learn Flexbox in 15 Minutes
Web Dev Simplified
Custom Checkbox Tutorial
Web Dev Simplified
Start Contributing to Open Source (Hacktoberfest)
Web Dev Simplified
JavaScript Shopping Cart Tutorial for Beginners
Web Dev Simplified
Responsive Video Background Tutorial
Web Dev Simplified
1,000 Subscriber Giveaway
Web Dev Simplified
How To Prevent The Most Common Cross Site Scripting Attack
Web Dev Simplified
Transparent Login Form Tutorial
Web Dev Simplified
The Forgotten CSS Position
Web Dev Simplified
How to Code a Card Matching Game
Web Dev Simplified
10 Must Install Visual Studio Code Extensions
Web Dev Simplified
Learn CSS Grid in 20 Minutes
Web Dev Simplified
Learn JSON in 10 Minutes
Web Dev Simplified
10 Essential Keyboard Shortcuts For Programmers
Web Dev Simplified
What Is The Fastest Way To Load JavaScript
Web Dev Simplified
Differences Between Var, Let, and Const
Web Dev Simplified
How To Install MySQL (Server and Workbench)
Web Dev Simplified
Learn SQL In 60 Minutes
Web Dev Simplified
How To Solve SQL Problems
Web Dev Simplified
What Are Design Patterns?
Web Dev Simplified
Null Object Pattern - Design Patterns
Web Dev Simplified
Your First Node.js Web Server
Web Dev Simplified
How To Setup Payments With Node.js And Stripe
Web Dev Simplified
How To Learn Any New Programming Skill Fast
Web Dev Simplified
Asynchronous Vs Synchronous Programming
Web Dev Simplified
JavaScript ES6 Arrow Functions Tutorial
Web Dev Simplified
Are You Too Old To Learn Programming?
Web Dev Simplified
JavaScript Cookies vs Local Storage vs Session Storage
Web Dev Simplified
JavaScript Promises In 10 Minutes
Web Dev Simplified
Builder Pattern - Design Patterns
Web Dev Simplified
JavaScript == VS ===
Web Dev Simplified
JavaScript ES6 Modules
Web Dev Simplified
8 Must Know JavaScript Array Methods
Web Dev Simplified
CSS Variables Tutorial
Web Dev Simplified
JavaScript Async Await
Web Dev Simplified
How To Choose Your First Programming Language
Web Dev Simplified
Easiest Way To Work With Web Fonts
Web Dev Simplified
Singleton Pattern - Design Patterns
Web Dev Simplified
Responsive Navbar Tutorial
Web Dev Simplified
CSS Progress Bar Tutorial
Web Dev Simplified
Learn GraphQL In 40 Minutes
Web Dev Simplified
What is an API?
Web Dev Simplified
Learn How To Build A Website In 1 Hour!
Web Dev Simplified
Related AI Lessons
⚡
⚡
⚡
⚡
Had my Frontend Developer interview with Capgemini (Application Developer) today, and I wanted to…
Medium · JavaScript
10 Frontend Developer Tools to Boost Productivity in 2026
Medium · Programming
10 Frontend Developer Tools to Boost Productivity in 2026
Medium · JavaScript
The US Frontend Engineer Market in 2026: A Data-Driven Reality Check (and the Bias That Stops Us Seeing It)
Dev.to AI
🎓
Tutor Explanation
DeepCamp AI