function foo() { return [1,2,3]; } var [a,b,c] = foo(); console.log(a,b,c) // 1 2 3
function f6({x=10}={},{y}={y:10}){ console.log( x, y ); } f6(); // 10 10 f6( {}, {} ); // 10 undefined
function bar() { return { x: 4, y: 5, z:6 }; } var {x,y,z} = bar(); console.log( x, y, z ); // 4 5 6
functionfoo({x,y}) { console.log( x, y ); } foo( { y: 1, x: 2 } ); // 2 1 foo( { y: 42 } ); // undefined 42 foo( {} ); // undefined undefined
function f3([ x, y, ...z], ...w) { console.log( x, y, z, w ); } f3( [] ); // undefined undefined [] [] f3( [1,2,3,4], 5, 6 ); // 1 2 [3,4] [5,6]
function f6({x=10}={}, {y}={y:10}){ console.log( x, y ); } f6(); // 10 10 f6( {}, {} ); // 10 undefined
By Alexander Kozhevin
Polymath