0

I'm learning about cakephp, and I see much conditionals like:

if( x === y){
}

I've looked for it, but I don't find anything.

Dunhamzzz
  • 14,682
  • 4
  • 50
  • 74
Daniel Garcia Sanchez
  • 2,306
  • 5
  • 21
  • 35
  • http://stackoverflow.com/questions/359494/javascript-vs-does-it-matter-which-equal-operator-i-use – nikodz Feb 27 '13 at 09:07

2 Answers2

2

== wil do auto type conversion, === won't

This means that:

0 == "0" evaluates to TRUE, because internally when comparing strings and numbers, a string is converted to a number when using ==.

0 === "0" evaluates to FALSE, there is no type conversion done and a integer 0 is not equal to a string.

More info in the documentation and more documentation.

Bart Friederichs
  • 33,050
  • 15
  • 95
  • 195
  • Also 0 == "something" evaluates to true. That it the reason why its bad coding to not use strict comparison when working with strings or where it could be used. See the [last chapter](http://www.dereuromark.de/2013/01/22/cakephp-tips/) here for details. The rule should be "as strict as possible". – mark Feb 27 '13 at 09:11
2

== compares the values of two variables. If they are of different types, they are converted to a common type and then compared.

===, on the other hand, is more strict. It requires the two sides to be of the same type as well.

php> = 5 == "5"
true
php> = 5 === "5"
false
Blender
  • 289,723
  • 53
  • 439
  • 496