V
VK
RobG said:If the LHS is a variable, e.g.
var y = 'string'; // or the result of some function
then:
if ( y = typeof x )
will always be true. So maybe for typeof tests it is always better to
put typeof on the left because:
if (typeof x = ... )
will always give a syntax error regardless of what is on the other side
of the assignment operator, but the reverse is not the case.
That's really a game theory puzzle (~= artillerist vs. infantery man in
the most simplified form). By my observations it will "explode" with
higher probability on undefined values: so I prefer solutions A, C. But
as any game theory it's totally dependant on the "coin rules", then in
another situations solution B can be the best.
That's why I'd like to insistently repeat that ('undefined' == typeof
x) is NOT a sign of a "real programming experience", NOT proper vs.
wrong, NOT anything of this kind.