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
Sandeep Krishnan
9,730 PointsThe equality operator is "==" not "===" as mentioned in this video.
this was a question to the answer
4 Answers
Brendon Butler
4,254 PointsIn 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
Jesus Mendoza
23,289 Points=== is strict equal operator which checks if its equal and if its the same type
for example:
1 == '1' // true
1 === '1' // false
Sandeep Krishnan
9,730 Pointsthank you !
Sandeep Krishnan
9,730 PointsActually 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
Jesus Mendoza
23,289 PointsYou are right! But it's recommended to always use === to avoid unexpected behavior in your programs!
Jason Anello
Courses Plus Student 94,610 PointsOk, I misunderstood the question.
I thought you were suggesting that a correction was needed.
Sandeep Krishnan
9,730 PointsIf 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
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 PointsHi Sandeep,
Which video is this?