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

The equality operator is "==" not "===" as mentioned in this video.

this was a question to the answer

Hi Sandeep,

Which video is this?

4 Answers

In javascript there are three types of equal operators.

x = 5; // this will set the value of 'x' equal to '5'
x == 5; // this will check to see if the value of 'x' equals '5', which would return true
x === 5; // this will check to see if the value of 'x' equals '5' and that the type of value is the same, this would return true
// x is an integer type and 5 is an integer type so x equals 5, if you had this:
x === "5" // this would return false
x == "5" // but this would return true

resources: JavaScript Comparison and Logical Operators

=== is strict equal operator which checks if its equal and if its the same type

for example:

1 == '1' // true
1 === '1' // false

thank you !

Actually in the context of the video it is not necessary to have "===" operator because he is comparing a string to a string.... I am referring to the video -Introducing Conditional Statements by Dave McFarland

You are right! But it's recommended to always use === to avoid unexpected behavior in your programs!

Ok, I misunderstood the question.

I thought you were suggesting that a correction was needed.

If what scenarios would "==" be better ? I thought if you are writing a program where you want to compare strings then this might actually be the right thing to do...Like in this video