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


JavaScript Basics

What is the difference between double equals (==) and triple equals (===) in JavaScript?

1 Answer

Vincent Anildes
Vincent Anildes
4,748 Points

"The difference between == and === is usually characterized that == checks for value equality and === checks for both value and type equality. However, this is inaccurate. The proper way to characterize them is that == checks for value equality with coercion allowed, and === checks for value equality without allowing coercion; === is often called "strict equality" for this reason." From You Don't Know JS by Kyle Simpson

"Coercion" is when JS converts the value type implicitly (or automatically.) So for example:

var a = 1; //number
var b = "1"; //string

a == b //true, because JS has converted the data type of "1" from a string to a number implicitly.
a === b //false, because JS has NOT converted the data type of "1" from string to number. === Does not allow it.

tldr: == checks if values are equal and allows coercion, === checks if values are equal and does NOT allow coercion.