Javascript Change two variables. How it works?

Saw in the following source:

[param_o,param_got] = [param_got,param_o];

This code changes the variables param_oand param_got. But how does it work [param_o,param_got] = [param_got,param_o]if it []is a new instance Arrayin Javascript?

EDIT Try to check:

var param_o = 1;
var param_got = 2;
[param_o,param_got] = [param_got,param_o];
console.log(param_o+" "+param_got);

// 2 1
+3
source share
1 answer

This notation is called destructuring assignment and is part of Javascript 1.7:

The purpose of destructuring allows you to extract data from arrays or objects using syntax that reflects the design of the array and object literals.

. , , . .

, , .

, , , .

Firefox Firefox 2 . Chrome - 3 . IE11 , .

+5

All Articles