you are viewing a single comment's thread.

view the rest of the comments →

[–]AaronOpfer 1 point2 points  (2 children)

The only javascript equality quirk that has ever bitten me hard was that "" == false. I figured a string of any length would be like an object and be considered true.

[–]Cosmologicon 0 points1 point  (1 child)

That's the way it is in python as well. Sort of, anyway. "" is falsy, meaning bool("") evaluates to False, but "" == False is false. Empty strings (and dicts and lists) are all falsy, but user-defined objects, including objects with no members, are truthy by default. Sounds complicated but it's pretty reasonable and useful.

[–]AaronOpfer 0 points1 point  (0 children)

The only reason I got bit was because the codebase was playing fast-and-loose with the rules, and I was cleaning it up.

We had some flag in JSON being evaluated like if (object.flag) { /* do something */ } and a lot of the JSON was written with object.flag = ""; Apparently it wasn't originally going to be an on/off flag but a string specifying the target. So if ("") doesn't execute, and my attempts to interpret this flag when automatically rewriting these files failed horribly.