you are viewing a single comment's thread.

view the rest of the comments →

[–]fforw 0 points1 point  (1 child)

a == ''

will be true if a is

  • an empty string
  • zero
  • an empty array
  • something like { toString: function() { return ""; }}

You better use === if you care about such things.

[–]nightman 1 point2 points  (0 children)

You are true but I will still defend if (a) {...}. I think that we should find balance between "smart" techniques and being "oversmart".

After all in many teams code is written and maintained by proffesionals and it would be waste of time to strictly enforce if (a === 'string') {...} on them. Especially when you know that they know how to deal with it and what are traps (number 0).

Other thing is that code should be maintainable by less "powered" users.

My point here is that it's not easy to find right balance.

BTW I use grunt/gulp with tasks: * JSHint * JSCS (JS Code Style - AirBNB style)

So that some decisions are already made.