Normally to swap two variables you need a temporary variable because when the first variable is reassigned you lose the value.
leta='apple';letb='orange';lettmp=a;a=b;b=temp;
We have the syntax available to perform a swap without need an intermediate variable.
leta='apple';letb='orange';[a,b]=[b,a];console.log(a);// orangeconsole.log(b);// apple
Javascript destructuring enable variable swapping without need an intermediate variable.
Cheers mates!
Top comments(0)
Subscribe
For further actions, you may consider blocking this person and/orreporting abuse