/    Sign up×
Community /Pin to ProfileBookmark

Difference between == and === ?

What’s the difference between == and === ?
and
What’s the difference between != and !== ?

And why would I use one instead of the other?

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@ShrineDesignsMay 11.2005 — == equal to

!= not equal to

=== identical to

!== not identical to

the difference, == test if the equation on the left and right are equal to one another even if they are of different types, whereas, === check if they are identical both value and type
Copy linkTweet thisAlerts:
@bokehauthorMay 11.2005 — Do you mean like this:
[code=php]
if(1+2 == 3) { //TRUE
}
if(1+2 === 3) { //FALSE
}
[/code]
Copy linkTweet thisAlerts:
@felgallMay 11.2005 — They would both be true because they are all numbers and equal/identical values.

It gives different results when the two sides are different types eg numeric and boolean for example:
if(12 == true) { //TRUE because only 0 evaluates as false
}
if(12 === true) { //FALSE because they are not the same type
}
Copy linkTweet thisAlerts:
@ShrineDesignsMay 11.2005 — more like[code=php]<?php
if(1 == true)
{
echo '1 is equal to true<br>';
}
if(1 === true)
{
echo '1 is identical to true<br>';
}
if(1 != true)
{
echo '1 not is not equal to true<br>';
}
if(1 !== true)
{
echo '1 is not identical to true<br>';
}
?>[/code]
Copy linkTweet thisAlerts:
@JonaMay 13.2005 — [font=Trebuchet MS]For the record, this is true of PHP and other languages with similar syntax (including JavaScript).[/font]
×

Success!

Help @bokeh spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...