Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Jose Linares
5,062 Points== vs ===
Hi, I'd like to know what's the difference between using == and === in javascript. Thanks
1 Answer
Marcus Parsons
15,719 PointsHi Jose,
A == is a non-strict comparison of two values while === is a strict comparison. When I say non-strict and strict, what I mean is that non-strict comparisons force conversion of one type into another to see if the two values are the same while strict comparisons check to see if both the type and value are the same, no conversions are done.
i.e.
Logic Tests
//Run these in your console;
console.log(3=="3"); //returns true, the string 3 is converted into type number and then checked
console.log(3==="3"); //returns false, the string 3 does not equal the number 3, both type and value must match
It is a best practice to use strict comparisons in your code, though, because of some whacky conversions that happen when using ==.
Jose Linares
5,062 PointsJose Linares
5,062 PointsThanks. That was really helpful.
Marcus Parsons
15,719 PointsMarcus Parsons
15,719 PointsYou are very welcome, Jose. Happy Coding! ^_^