JavaScript DESTRUCTURING in 8 minutes! 💥

  Рет қаралды 13,669

Bro Code

Bro Code

Күн бұрын

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);

Пікірлер: 25
@BroCodez
@BroCodez 7 ай бұрын
// 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);
@Dj7wiLLY
@Dj7wiLLY 3 ай бұрын
Extraordinary well explained and examples were very good. Thank you so much!
@user-qj1lq4zx3p
@user-qj1lq4zx3p 5 ай бұрын
Great job Bro Code! I became addicted to your tutorials. I admire the amount of work you invest in developing these learning materials.
@robertweekes5783
@robertweekes5783 4 ай бұрын
Thanks for showing this with arrays first, makes it easier to understand
@zaklettrezvenik
@zaklettrezvenik 2 ай бұрын
Patric is coding ever since dropping out of spongebob show, its expected of him to pop up again somewhere in apple
@skootdiggity1301
@skootdiggity1301 25 күн бұрын
Fairly convincing human voice on this AI.
@tonytodd7011
@tonytodd7011 7 ай бұрын
Thanks Bro for your simple but great explanation!
@Mostafa-jh2ij
@Mostafa-jh2ij 11 күн бұрын
Really awesome, bro thanks a bunch!
@ranasif
@ranasif 4 ай бұрын
Great video, thanks!
@copurdy6931
@copurdy6931 Ай бұрын
Thanks you so much bro, you teach so detail and i can understand now
@suryar6137
@suryar6137 3 ай бұрын
very great tutorial
@shivanshuhere
@shivanshuhere 6 ай бұрын
Smooth
@tamilmukbang3789
@tamilmukbang3789 Ай бұрын
thank you bro
@hunin27
@hunin27 7 ай бұрын
hey these are actually pretty useful tutorials, they touch more advanced topics than the other videos. are these old? or are they new videos? Thanks for everything bro ❤
@xzex2609
@xzex2609 7 ай бұрын
there is a complete java script 8 Hours , and these series are new. Bro uses different way of doing things in this series , but both are great . and I hope he Dive into Dom more deeper , cause js is the language of controlling DOM at least this is the way I see it : you got to be crazy to use this language for writing apps . I don't know maybe libraries change my mind around this . but in python from the get go you are armed with any tool you need to do what ever you want.
@mohsenmk2537
@mohsenmk2537 7 ай бұрын
😘thank you
@shafiq_ramli
@shafiq_ramli 7 ай бұрын
What about destructuring object inside an object? Hope you can make a video about that soon!
@xzex2609
@xzex2609 7 ай бұрын
can we use this or rest operator to deliver different amount of arguments like in python when we use (*args , **kwargs) ? destructuring is like unpacking , but is there such a feature in JS I'm really having a hard time with the language coming from python , I wonder if it was better to learn Django
@ghorlik432
@ghorlik432 7 ай бұрын
What about "this" or static in obj ?
@_Sahil-ru3lp
@_Sahil-ru3lp 7 ай бұрын
The patrick in the object destruction example is me 😢😢
@nihongo_
@nihongo_ 3 ай бұрын
W
@MCroppered
@MCroppered 4 ай бұрын
Is that your normal voice?
@lobomalsano
@lobomalsano 2 ай бұрын
I think he deliberately makes his voice a little bit deeper to go with his theme of a "bro". That has to strain his throat lol
@user-mo6yo4kz1m
@user-mo6yo4kz1m 2 ай бұрын
@@lobomalsano its his normal voice
@STR-DP
@STR-DP 3 ай бұрын
37😜
Learn JavaScript NESTED OBJECTS easy! 📫
9:14
Bro Code
Рет қаралды 7 М.
JavaScript forEach() method in 8 minutes! ➿
8:02
Bro Code
Рет қаралды 23 М.
The joker's house has been invaded by a pseudo-human#joker #shorts
00:39
Untitled Joker
Рет қаралды 5 МЛН
OMG🤪 #tiktok #shorts #potapova_blog
00:50
Potapova_blog
Рет қаралды 17 МЛН
WHO DO I LOVE MOST?
00:22
dednahype
Рет қаралды 23 МЛН
Must-have gadget for every toilet! 🤩 #gadget
00:27
GiGaZoom
Рет қаралды 11 МЛН
Learn JavaScript Destructuring in 20 minutes (For Beginners)
20:29
Sonny Sangha
Рет қаралды 16 М.
Why Signals Are Better Than React Hooks
16:30
Web Dev Simplified
Рет қаралды 456 М.
The JavaScript SUPER keyword is super! 🦸‍♂️
9:22
Bro Code
Рет қаралды 11 М.
How to FETCH data from an API using JavaScript ↩️
14:17
Bro Code
Рет қаралды 92 М.
JavaScript map() method in 7 minutes! 🗺
7:01
Bro Code
Рет қаралды 25 М.
Learn JavaScript ARROW FUNCTIONS in 8 minutes! 🎯
8:02
Bro Code
Рет қаралды 22 М.
The different types of JavaScript functions explained
14:47
Kevin Powell
Рет қаралды 36 М.
Why Is Array/Object Destructuring So Useful And How To Use It
13:24
Web Dev Simplified
Рет қаралды 420 М.
Learn JavaScript ARRAYS in 8 minutes! 🗃
8:06
Bro Code
Рет қаралды 22 М.
The joker's house has been invaded by a pseudo-human#joker #shorts
00:39
Untitled Joker
Рет қаралды 5 МЛН