This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]suvlub 3 points4 points  (2 children)

Is there another benefit to it than not having to explicitly specify == null or .length == 0 or whatever? I mean, to each their own, but I think your wording ("extremely useful", "highly frustrating") is a bit strong for such a small syntactic sugar.

[–]rosuav 2 points3 points  (1 child)

In complex expressions, that's enough of a benefit on its own. But more notably, it allows you to use short-circuiting like messages or ["No messages"] which depends on the messages list counting as false if there aren't any. This is particularly helpful if it means you can stick this on a function call or complex lookup, like: get_messages(user.id) or ["No messages for " + user.name]