17
urco
8y

Javascript is so funny

"0" == 0 //true
"" == 0 //true
"0" == "" //false

Always remember the ===
Realize this took me an hour of debugging

Comments
  • 0
    This is also in other languages isn't it?
  • 0
    So, Should I always use ===?
  • 0
    In many languages is implemented the === (JS, PHP, Ruby) @GC97 and basically means that is comparing the Class and the value, so it might be cases that you want to compare only the values @GurpreetSK95
  • 1
    This makes sense since the string 0 is not a falsy value in JavaScript.
  • 1
    So much garbage in this language, I don't know why everyone has such a hard on for it.
  • 0
    @edisonn ewwww. <> is the worst or operator
  • 1
    @urco Or you can just learn about implicit type conversion which happens in almost all dynamic languages. Its better when you understand why something is happening than just putting it up as "oh its just the language X acting all rowdy today") :)
Add Comment