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 AJAX Basics (retiring) jQuery and AJAX The Office Status Project Revisited

Gi Devs
Gi Devs
12,171 Points

Why use ===

during this course a few times now I have noticed that we use if(employee.inoffice === true). employee.inoffice returns a boolean value so what would we need to add the strict equals rather than just asking for the value.

3 Answers

Mahmoud Dafer
Mahmoud Dafer
9,793 Points

inoffice is a property that could take true or false(boolean), it is like asking:" is he in the office?" and not telling that he is in the office. So, this is why we should write === false or true to tell whether he is in or not

anil rahman
anil rahman
7,786 Points

The == does type conversion but the === does not do the type conversion.

So

 true == 1 //this will be true

It's because the == does the conversion when comparing so it basically says 1 convert into a true.

On the other hand

true === 1 //false

It's because there is no conversion so it makes sure that what you are checking against is exactly right and not close or close enough to switch to what it should be in the first place.

//It would need to be like this to be true
true === true
Gi Devs
Gi Devs
12,171 Points

but you wouldn't need == either. what I'm saying is if(employee.inoffice){ function code} can stand alone

anil rahman
anil rahman
7,786 Points

Maybe it's just their way of showing us as beginners and intermediates to make sure we understand it fully rather than using short hand conditionals or something because you are right just using inOffice boolean would equate to true and go into the function if actually was true. Maybe the instructor himself/herself enjoys writing it that way.