JavaScript “Syntactic Sugar”
I’ve just been glancing over this post about JavaScript syntax goodies (aka sugar) on StackOverflow. Two highlights were:
Defaults
I’ve been jealous of ruby having this method - php doesn’t have an equally succinct equivelant - however it appears Javascript does.
arg = arg || 'default'; // if arg evaluates to false, use 'default'
Object Membership Test
A nice, natural way to check for object members.
var props = { a: 1, b: 2 };
("a" in props) // true
("b" in props) // true
("c" in props) // false
