Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

JavaScript Using es6(ES2015) Destructuring assignment

//JavaScript program to swap two variables

//take input from the users
let a = prompt('Enter the first variable: ');
let b = prompt('Enter the second variable: ');

//using destructuring assignment
[a, b] = [b, a];

console.log(`The value of a after swapping: ${a}`);
console.log(`The value of b after swapping: ${b}`);
Source by developer.mozilla.org #
 
PREVIOUS NEXT
Tagged: #JavaScript #Using #Destructuring #assignment
ADD COMMENT
Topic
Name
3+5 =