Considering the following snap of code, what is the expected result?
let dogName = 'Tom';
let catName = 'Jerry';
[dogName, catName] = [catName, dogName];
console.log(`Dog name: ${dogName}`);
Considering the following snap of code, what is the expected result?
let dogName = 'Tom';
let catName = 'Jerry';
[dogName, catName] = [catName, dogName];
console.log(`Dog name: ${dogName}`);
let dogName = 'Tom';
let catName = 'Jerry';
[dogName, catName] = [catName, dogName];
console.log(`Dog name: ${dogName}`);
On third line the values of dogName and catName variable will be swap. In EcmaScript 6 (ES6) we don't need a third variable to swap values of two different variable.