Premium Only Content

JavaScript DESTRUCTURING in 8 minutes! 💥
00:00:00 intro
00:00:21 swap the values of two variables
00:01:11 swap two elements in an array
00:02:34 assign array elements to variables
00:03:47 extract values from objects
00:06:11 destructuring in function parameters
// destructuring = extract values from arrays and objects,
// then assign them to variables in a convenient way
// [] = to perform array destructuring
// {} = to perform object destructuring
// --------- EXAMPLE 1 ---------
// SWAP THE VALUE OF TWO VARIABLES
let a = 1;
let b = 2;
[a, b] = [b, a];
console.log(a);
console.log(b);
// --------- EXAMPLE 2 ---------
// SWAP 2 ELEMENTS IN AN ARRAY
const colors = ['red', 'green', 'blue', 'black', 'white'];
[colors[0], colors[4]] = [colors[4], colors[0]]
console.log(colors);
// --------- EXAMPLE 3 ---------
// ASSIGN ARRAY ELEMENTS TO VARIABLES
const [firstColor, secondColor, thirdColor, ...extraColors] = colors;
console.log(firstColor);
console.log(secondColor);
console.log(thirdColor);
console.log(extraColors);
// --------- EXAMPLE 4 ---------
// EXTRACT VALUES FROM OBJECTS
const person1 = {
firstName: 'Spongebob',
lastName: 'Squarepants',
age: 30,
job: "Fry cook",
};
const person2 = {
firstName: 'Patrick',
lastName: 'Star',
age: 34
};
const {firstName, lastName, age, job="Unemployed"} = person2;
console.log(firstName);
console.log(lastName);
console.log(age);
console.log(job);
// --------- EXAMPLE 5 ---------
// DESTRUCTURING IN FUNCTION PARAMETERS
function displayPerson({ firstName, lastName, age, job="Unemployed" }) {
console.log(`name: ${firstName} ${lastName}`);
console.log(`age: ${age}`);
console.log(`job: ${job}`);
}
displayPerson(person1);
displayPerson(person2);
-
UPCOMING
BEK TV
2 days agoTrent Loos in the Morning - 9/08/2025
97 -
LIVE
The Bubba Army
2 days agoDocumentary Premiere, A HUGE SUCCESS! - Bubba the Love Sponge® Show | 9/08/25
5,381 watching -
32:15
DeVory Darkins
7 hours ago $3.35 earnedDemocrats PAINFULLY WRECKED by Tom Homan as paid protesters ERUPT in Chicago
3.11K24 -
16:59
Degenerate Jay
12 hours ago $0.92 earnedIs Metal Gear Solid Delta: Snake Eater Worth Buying?
18.2K2 -
LIVE
Flex011
4 hours ago $0.05 earnedCronos: The New Dawn – Brutal Time-Travel Horror Survival
40 watching -
33:11
The Finance Hub
16 hours ago $0.72 earnedBREAKING: JD VANCE JUST RELEASED A MASSIVE BOMBSHELL!!! OMG!!
1.74K16 -
18:06
Professor Gerdes Explains 🇺🇦
14 hours agoAfter Major Attack, Trump Vows "Phase II" Sanctions on Russia
3.78K7 -
LIVE
EVASIVE_rabbi
4 hours ago✅️ 2 Dumb Navy Vets & A First Playthrough #Coop ✅️
55 watching -
LIVE
Cook14u
8 hours agoSeahawks Let Me Down, DO NOT Talk About How I Look 🤐🙃🥴
22 watching -
8:18
MattMorseTV
15 hours ago $9.28 earned2.2 MILLION in ONE YEAR.
64.4K145