JavaScript DESTRUCTURING in 8 minutes! 💥

Поділитися
Вставка
  • Опубліковано 15 лис 2024

КОМЕНТАРІ • 39

  • @BroCodez
    @BroCodez  Рік тому +8

    // 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 7 місяців тому +7

    Extraordinary well explained and examples were very good. Thank you so much!

  • @vladimirAleksic-g5q
    @vladimirAleksic-g5q 10 місяців тому +6

    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 9 місяців тому +3

    Thanks for showing this with arrays first, makes it easier to understand

  • @ramzyabdul185
    @ramzyabdul185 6 днів тому

    Now this is solid explanation, I was starting it today and had some unclear parts on the function part... But u made it clear for me thanks bro

  • @mehrnoushghaffarzadeh4971
    @mehrnoushghaffarzadeh4971 4 місяці тому +2

    You teach really well! Thank you so ,much for this tutorial. Helped a lot!

  • @sriramannadurai9287
    @sriramannadurai9287 2 місяці тому +7

    Who else is here after starting useState hook in react js without knowing JavaScript in depth like me ? 😂

    • @MohammedAli-p7e9d
      @MohammedAli-p7e9d 2 місяці тому +2

      Is this topic important in react js?

    • @Muhammad-Bilal0055
      @Muhammad-Bilal0055 2 місяці тому

      ​@@MohammedAli-p7e9d yes

    • @Darealdivine
      @Darealdivine 2 місяці тому

      ​@@MohammedAli-p7e9d Yes

    • @sriramannadurai9287
      @sriramannadurai9287 2 місяці тому

      @@MohammedAli-p7e9d To understand useState() you need to know how destructuring works.

    • @RABWA333
      @RABWA333 Місяць тому

      @@MohammedAli-p7e9d yes, even when you fetch data from API and get json object you will need this , a lot more cases as well in React , actually you have to learn this topic and dive more in it

  • @skootdiggity1301
    @skootdiggity1301 5 місяців тому +2

    Fairly convincing human voice on this AI.

  • @kaylinburchette575
    @kaylinburchette575 Місяць тому

    Wow! Great video. 😄 Very explanatory, finally understood this topic

  • @tonytodd7011
    @tonytodd7011 Рік тому +1

    Thanks Bro for your simple but great explanation!

  • @piotrmazgaj
    @piotrmazgaj 2 місяці тому

    This is my seal. I have watched the entire video, understood it, and I can explain it in my own words, thus I have gained knowledge. This is my seal.

  • @omatzi7251
    @omatzi7251 Місяць тому

    when object destructuring the new variables can have a different name than the object keys, for example: const {firstName: personName}; (firstName - object key, personName - new variable)

  • @zaklettrezvenik
    @zaklettrezvenik 7 місяців тому +2

    Patric is coding ever since dropping out of spongebob show, its expected of him to pop up again somewhere in apple

  • @mohammadsuhaanhaq3590
    @mohammadsuhaanhaq3590 3 місяці тому +1

    really helpful video thanks😃

  • @copurdy6931
    @copurdy6931 6 місяців тому

    Thanks you so much bro, you teach so detail and i can understand now

  • @Mostafa-jh2ij
    @Mostafa-jh2ij 5 місяців тому

    Really awesome, bro thanks a bunch!

  • @ranasif
    @ranasif 8 місяців тому

    Great video, thanks!

  • @suryar6137
    @suryar6137 7 місяців тому

    very great tutorial

  • @shafiq_ramli
    @shafiq_ramli 11 місяців тому

    What about destructuring object inside an object? Hope you can make a video about that soon!

  • @hunin27
    @hunin27 Рік тому

    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 Рік тому

      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.

  • @ocs7
    @ocs7 3 місяці тому +1

    goat

  • @_Sahil-ru3lp
    @_Sahil-ru3lp Рік тому

    The patrick in the object destruction example is me 😢😢

  • @shivanshuhere
    @shivanshuhere 10 місяців тому +1

    Smooth

  • @xzex2609
    @xzex2609 Рік тому

    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

  • @tamilmukbang3789
    @tamilmukbang3789 6 місяців тому

    thank you bro

  • @mohsenmk2537
    @mohsenmk2537 Рік тому

    😘thank you

  • @ghorlik432
    @ghorlik432 Рік тому

    What about "this" or static in obj ?

  • @nihongo_
    @nihongo_ 7 місяців тому

    W

  • @MCroppered
    @MCroppered 8 місяців тому

    Is that your normal voice?

    • @lobomalsano
      @lobomalsano 7 місяців тому

      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 7 місяців тому

      @@lobomalsano its his normal voice

  • @STR-DP
    @STR-DP 8 місяців тому

    37😜