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);
-
2:47:03
Patriot Underground
16 hours agoTruthStream RT w/ Joe & Scott (7.30.25 @ 5PM EST)
25.1K24 -
11:25
Nikko Ortiz
13 hours agoMost Painful Fails
13.1K23 -
16:23
GritsGG
13 hours agoWorld Record Call of Duty Win Streak Attempting!
3.16K1 -
2:02:54
Side Scrollers Podcast
18 hours agoJOEY SWOLL/HULK HOGAN CONTROVERSY + ONLINE SAFETY ACT + MORE | SIDE SCROLLERS
25.9K2 -
1:05:44
Omar Elattar
9 months agoThe Digital Real Estate Expert: You're Being Lied To About Making Money Online!
4.61K -
10:53
Nikko Ortiz
2 days agoWORST Clips On The Internet
86K27 -
3:42:38
FreshandFit
12 hours agoREAL R*pe Victim Exposes Shannon Sharpe Accuser As Liar!
70.1K76 -
2:18:29
Badlands Media
14 hours agoDevolution Power Hour Ep. 376: Optics, Explosions & the War for the Narrative
144K43 -
37:46
Stephen Gardner
12 hours ago🔥Trump NEVER expected THIS WIN as Schumer has EPIC MELTDOWN!
44K34 -
2:02:41
Inverted World Live
9 hours agoNASA Engineer Says Trillions of Shape-Shifting, Cloaked Devices are Hidden on Earth| Ep. 83
39K11