JavaScript is exemplary of the fact that being at the right place at the right time can take you to great heights. Even with obvious design flaws — like this, for instance — it has went on to become, in Jeff Atwood's words, the world's most ubiquitous computing runtime, and that is my favorite thing about JavaScript.
Speaking in terms of the language construct, closures have a special place in the list of all of my favourite things.
I knew about the concept of closures from the time I spent with Python; but when I happened at them again, while going through Crockford's book ... I can't quite zero in on the reason; the simplicity of the following example, had won my heart.
var myObject = (function () {
var value = 0;
return {
increment: function (inc) {
value += typeof inc === 'number' ? inc : 1;
},
getValue: function () {
return value;
}
};
}());