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 JavaScript Basics (Retired) Making Decisions with Conditional Statements Introducing Conditional Statements

Lukas Muller
Lukas Muller
7,347 Points

Why are three equal signs used?

I know that it can't be just one, because this is used for actually assigning something to a variable or whatever it may be. But why aren't two equal signs used instead of the here shown three (like in Swift)?

4 Answers

x = y is "variable X has a value of y"

x == y is checking if x has the same value of y

x === y is checking if x has the same value and same data type of y.

The last one is a bit safer. One misconception about JavaScript is that it is non-typed when it is in fact loosely typed.

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Lukas;

Take a look at my post here and see if it helps to clear anything up.

Post back with further questions.

Ken

Sam Baines
Sam Baines
4,315 Points

Your post is a much clearer and better explanation Ken, thanks for drawing my attention to it also.

Sam Baines
Sam Baines
4,315 Points

I am unsure what you are actually asking in this question - basically Javascript uses both == and === for equal and strict equal I believe - for a more in depth explanation look at this link.

Ivan Saveliev
Ivan Saveliev
9,153 Points

I believe it's already answered, just wanted to put my 2 cents here. Don't underestimate the MDN, it's a great reference:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators

Lukas Muller
Lukas Muller
7,347 Points

Hi Ivan,

This post is quite old. Thanks anyways! Have used the MDN quite often while studying.

Thanks again!