Mascara Try it Download Buy About Documentation Blog

Destructuring assignment

Destructuring assignments are a very convenient syntax for "unpacking" arrays or object. It allows you to write eg.:
var [a, b] = [1,2];
This is especially useful when returning arrays from a function, e.g.:
function f() { return [1, 2]; }
var [a,b] = f();

Objects can be unpacked by extracting individual properties, e.g.

var point = {x:10, y:100};
var {x:xpos, y:ypos} = point;
The above reads point.x into xpos and point.y into ypos.