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

PHP PHP Basics (Retired) PHP Conditionals & Loops Conditionals

== vs ===

In JavaScript (which so far seems very similar to php) Dave strongly encouraged to ALWAYS use === as opposed to ==. So I'm wondering is it ok to always use === in php also?

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

I'd say yes. Because in both languages it means essentially the same thing. The double equal means equal to. The triple equal means identical. Let's put it this way. You have in JavaScript and other languages the idea of truthy or falsey. We could have a comparison like this:

var x = 0;

var isFalsey = x == false;
var isFalsey2 = x === false;

If you run that in the console you'll see that the first isFalsey returns true. The second one returns false. This is because while x is falsey it is not explicitly equal to (or identical) to false. Using the explicitly equals to/identical to is a great way to ensure that you're checking for what you're intending to check for and that your code behaves the way you intend it to.

Thanks Jennifer.