Where else can variables be used like this?
I will tell you a little where they can be used in the near future (you never know, maybe someone does not know)
Destructuring assignment:
var a = 1, b = 2; [a, b] = [b, a]; // или например так: var { x:a, y:b } = { x:1, y:2 };
Where can this be useful? example from backbone.js sources:
set: function(key, value, options) { var attrs, attr, val; if (_.isObject(key) || key == null) { attrs = key; options = value; } else { attrs = {}; attrs[key] = value; }
the if
body can be easily replaced by:
[attrs, options] = [key, value]
Generator Expressions:
[ i for ( i in [5,6,7,8,9] ) ] // [0,1,2,3,4] [ i for each ( i in [5,6,7,8,9] ) ] // [5,6,7,8,9] [ i for each ( i in [5,6,7,8,9] ) if (i % 2 != 0)] // [5,7,9]
besides spheres of application is enough
Optional named function arguments
function foo({ name:name, project:project}) { console.log(project); console.log(name); } foo({ name:'soubok', project:'jslibs' }); foo({ project:'jslibs', name:'soubok'});
more details: