JavaScript spread operator and rest parameters tutorial ES6 / ES2015

แชร์
ฝัง
  • เผยแพร่เมื่อ 11 ม.ค. 2025

ความคิดเห็น • 110

  • @akhileshguptaakhi
    @akhileshguptaakhi 4 ปีที่แล้ว +9

    Perhaps you might want to also include below syntax too for merging arrays, assuming a and b are also arrays
    var c = [...a,...b]

  • @Vivaxsolutions
    @Vivaxsolutions 7 ปีที่แล้ว +5

    techsith, time and again, shows that teaching is a gift; amazing examples - and to the point. Well done! Your work, time and effort in producing them are fully appreciated.

  • @kazaakas
    @kazaakas 6 ปีที่แล้ว +2

    3:17
    You should do this with Array.from(arguments);
    Also, parameters can be left out entirely if you were to do it the other way:
    Array.prototype.slice.call(arguments);

  • @malbu22
    @malbu22 6 ปีที่แล้ว

    Great video - I see this operator used all over the place in projects at work. This is the best explanation I have seen! And who doesn't love toast?!

  • @RickyGarcia_Learning
    @RickyGarcia_Learning 8 ปีที่แล้ว +40

    Dear lord, that thumbnail.

    • @Techsithtube
      @Techsithtube  8 ปีที่แล้ว +15

      Rick , in this crazy world of cat meme i found irresistible not to use this thumbnail. :)

    • @danial9864
      @danial9864 4 ปีที่แล้ว +1

      How else can he catch your attention? lol

  • @Carl-yu6uw
    @Carl-yu6uw 5 ปีที่แล้ว +1

    1.16 it is actually the rest operator in that scenario, as you are collecting unknown quantity of arguments into the new array n. Opposite use, i.e. to dismember an array, but used in a function call would be the spread operator.

  • @threeone6012
    @threeone6012 5 ปีที่แล้ว +1

    I give every techsith video a thumbs up.
    Always good.

  • @sup1075
    @sup1075 ปีที่แล้ว

    That's amasing and really helpfull video, It's must be in top!

  • @vinkrins
    @vinkrins 6 ปีที่แล้ว +1

    Can't stop watching your videos, I am addicted and subscribed :D

    • @Techsithtube
      @Techsithtube  6 ปีที่แล้ว

      Thanks for subscribing Vinay!

  • @sophialee3713
    @sophialee3713 5 ปีที่แล้ว +7

    'go to heaven' didn't expect that come out 😂🤣

    • @madimakes
      @madimakes 4 ปีที่แล้ว +1

      i was like "wow this is gonna get morbid...wait..wut"

    • @teenytinytoons
      @teenytinytoons 3 ปีที่แล้ว

      it got real, real quick.

  • @cynthiaclinton5148
    @cynthiaclinton5148 5 ปีที่แล้ว +3

    Thank you, great explanation on spread operator and rest parameter!

    • @Techsithtube
      @Techsithtube  5 ปีที่แล้ว +1

      Thanks for watching cynthia. Keep on learning!

  • @aseel1024
    @aseel1024 5 ปีที่แล้ว +1

    the big difference between the spread operator
    and the rest parameters
    is actually the place in which we use each of them.
    So the spread operator is used in the function call.
    While the rest operator is used in the function declaration.

  • @shay00795
    @shay00795 7 ปีที่แล้ว

    You have a great teaching style. Straight to the point and cover the major use cases real well! Thx!!

    • @Techsithtube
      @Techsithtube  7 ปีที่แล้ว

      Thanks for watching Shane !

  • @karthigadevi7227
    @karthigadevi7227 5 ปีที่แล้ว

    U re rocking..simply superb...need more videos.....I am not getting why 27 dislikes...

  • @MrWardo2009
    @MrWardo2009 3 ปีที่แล้ว

    Thank you for making this video!

  • @RodolfoRivera
    @RodolfoRivera 8 ปีที่แล้ว +1

    I just stumbled upon your channel: Thank You!

  • @jsnode2075
    @jsnode2075 7 ปีที่แล้ว +4

    ES6 is very very fucking important these days to learn frameworks.

    • @Techsithtube
      @Techsithtube  7 ปีที่แล้ว

      True that. new frameworks we only write in ES6 and later.

  • @ajotel94
    @ajotel94 7 ปีที่แล้ว +1

    You are sooooo greeeaaaat!..as I said before. :) You're doing great job with ES6!
    Looking forward for some TypeScript videos! ;)

    • @Techsithtube
      @Techsithtube  7 ปีที่แล้ว

      Thanks for watching! Will build tutorials for TypeScript. wait for few weeks :)

  • @mmmmmmm8706
    @mmmmmmm8706 5 ปีที่แล้ว

    Ok, i stand corrected, that is the best thumbnail on youtube! Sheesh, i wish we were in same team!

    • @Techsithtube
      @Techsithtube  5 ปีที่แล้ว

      Thanks for appreciating the thumbnail . I go through lot of thinking on each thumbnail. :)

  • @pratikchauhan9325
    @pratikchauhan9325 6 ปีที่แล้ว

    thanks brother you explained every use of spread operator.

  • @hemanthaabeywardena3442
    @hemanthaabeywardena3442 7 ปีที่แล้ว

    Brilliant, once again! techsith. I really appreciate your effort, time and vision.

    • @Techsithtube
      @Techsithtube  7 ปีที่แล้ว

      Thanks for watching ! :)

  • @hitanshimehta430
    @hitanshimehta430 5 ปีที่แล้ว +1

    Thank you for video!!!

  • @lloydlasrado
    @lloydlasrado 6 ปีที่แล้ว

    You remind of Dev Anand. Awesome videos as always

  • @Roudter
    @Roudter 6 ปีที่แล้ว +1

    Hey brother...I really like your videos. Thanks!

  • @dksivagis1
    @dksivagis1 8 ปีที่แล้ว +4

    Thanks sir.. your videos are the best for practice
    and gives us some ideas to think on real stuff.

  • @eternal_stoic_
    @eternal_stoic_ 4 ปีที่แล้ว

    good explanation thanks

  • @srogers500
    @srogers500 6 ปีที่แล้ว +2

    Very informative

  • @Beauty-2025
    @Beauty-2025 3 ปีที่แล้ว

    Awesome😍🙏🏽

  • @ErnestGWilsonII
    @ErnestGWilsonII 7 ปีที่แล้ว

    Thank you for another great video! I always click like / thumbs up and I am subscribed! I would like to see some real world examples (or additional examples) using the spread operator.

    • @Techsithtube
      @Techsithtube  7 ปีที่แล้ว +1

      That give me a cool idea to make a video on practical applications of spread operator. I will work on it . Thanks for watching!

  • @venkataramarajup2192
    @venkataramarajup2192 6 ปีที่แล้ว

    hi sir,here in this example the values inside the function x,will it be used????

  • @amirkahinpour547
    @amirkahinpour547 6 ปีที่แล้ว +1

    YouReAwesome= ["you're awesome", "best tutorial ever", "easy to follow"]; thankYou=["thank you sooo much",...YouReAwesome]; LOL

  • @SunilKumar-fh6jk
    @SunilKumar-fh6jk 6 ปีที่แล้ว

    clean and up to the point!

  • @Acid31337
    @Acid31337 8 ปีที่แล้ว +4

    [1,2,3].concat([4,5,6])
    not a big problem.
    … is really usefull as deep copy operator:
    b = { …a }

    • @Techsithtube
      @Techsithtube  8 ปีที่แล้ว +2

      yes. a good one. thanks for sharing.

    • @saurabhchauhan232
      @saurabhchauhan232 5 ปีที่แล้ว

      @gopher @@Techsithtube can you explain what is this, and what is deep copy here?

  • @yashwantkumar2592
    @yashwantkumar2592 3 ปีที่แล้ว

    We can use concate also to add to arrays in timestamp - 8:00 mins

    • @Techsithtube
      @Techsithtube  3 ปีที่แล้ว +1

      Yes concate also work well .

  • @Amitkumar-zp3wb
    @Amitkumar-zp3wb 5 ปีที่แล้ว +1

    He can joke with a straight face ... #BigRespectSir

  • @ShampooWow
    @ShampooWow 8 ปีที่แล้ว

    Awesome video! I like it

  • @HaiNguyen-cf1ji
    @HaiNguyen-cf1ji 5 ปีที่แล้ว +1

    I came for the thumbnail and stay for the content :)

    • @Techsithtube
      @Techsithtube  5 ปีที่แล้ว

      Cats are always fun for the thumbnails. :)

  • @jainshilpi3
    @jainshilpi3 7 ปีที่แล้ว

    thanku so much for this tutorial

  • @oskarkowalow8477
    @oskarkowalow8477 6 ปีที่แล้ว

    You can also transform an arguments object to array by Array.from(arguments)

    • @Techsithtube
      @Techsithtube  6 ปีที่แล้ว

      Yes, new Array.from method is quite handy.

  • @dod9652
    @dod9652 8 ปีที่แล้ว

    Very helpful videos.
    I like the idea of not having you in a small window at the right bottom corner any more but now you are floating on the screen background (-;

    • @Techsithtube
      @Techsithtube  8 ปีที่แล้ว

      +Do D Haha. I thought about too much before doing it. Do you prefer me on the left corner instead of right? (-;

  • @VinodMohananChelseaFC
    @VinodMohananChelseaFC 8 ปีที่แล้ว +2

    clean and to the point....

  • @AnythingGoesCodes
    @AnythingGoesCodes 6 ปีที่แล้ว +1

    4:38 i used it at work. my boss was not amused

    • @Techsithtube
      @Techsithtube  6 ปีที่แล้ว

      Is your boss old school? :)

  • @j.almadhaji
    @j.almadhaji 6 ปีที่แล้ว +2

    thank you sir

  • @santoshpasupunuri
    @santoshpasupunuri 6 ปีที่แล้ว +2

    Why is this video not viral!

  • @dksivagis1
    @dksivagis1 8 ปีที่แล้ว

    Hi sir... as requested, i am eagerly waiting if you can make a video on creating a sample JS API using the whole concepts you taught us.

    • @Techsithtube
      @Techsithtube  8 ปีที่แล้ว

      +Koteswara Siva Kumar Devineni Yes, I am going to make a video building a js api. wait for another two weeks . thanks.

    • @dksivagis1
      @dksivagis1 8 ปีที่แล้ว

      Or please suggest some book which helps in building JS API's, thank you

    • @Techsithtube
      @Techsithtube  8 ปีที่แล้ว

      Here is a good site showing how to build your own javascript lib. code.tutsplus.com/tutorials/build-your-first-javascript-library--net-26796

    • @dksivagis1
      @dksivagis1 8 ปีที่แล้ว +1

      +techsith Thank you sir .. i shall go through it. and also curious to see your video on the same subject thats going to come in 2 weeks. Because your way of teaching is very very unique.

  • @santoshpasupunuri
    @santoshpasupunuri 6 ปีที่แล้ว

    So, both rest and spread operators have the same syntax but do opposite task?

    • @Techsithtube
      @Techsithtube  6 ปีที่แล้ว +1

      think of this way, rest parameters nothing but when you pass parameters in a function using spread operator.

    • @santoshpasupunuri
      @santoshpasupunuri 6 ปีที่แล้ว

      nailed it

  • @amardeep18121986
    @amardeep18121986 6 ปีที่แล้ว

    Thanks a lot.

  • @sarainescalderon
    @sarainescalderon 8 ปีที่แล้ว +2

    thanks!

  • @GauthamHC99
    @GauthamHC99 4 ปีที่แล้ว

    Can anyone explain the difference between arguments and parameters in JavaScript.

    • @sjphs135
      @sjphs135 2 ปีที่แล้ว

      fun(a, b) { }
      fun(x, y);
      a, b are parameters
      x, y are arguments

  • @nofavors
    @nofavors 6 ปีที่แล้ว +2

    is that Randy Rhoads on you?

    • @Techsithtube
      @Techsithtube  6 ปีที่แล้ว +2

      Yes it is. It's an old tshirt

  • @bhanubaghel3012
    @bhanubaghel3012 5 ปีที่แล้ว +1

    👌

  • @jamjest444
    @jamjest444 6 ปีที่แล้ว +2

    It wasnt funny until he said it's a joke

  • @manojantony32
    @manojantony32 7 ปีที่แล้ว

    Understandable examples, please post more concepts on ES6 and TypeScript :)

    • @Techsithtube
      @Techsithtube  7 ปีที่แล้ว +1

      Will do thanks for watching!

  • @maheshsingh6787
    @maheshsingh6787 8 ปีที่แล้ว

    highly underrated, please do come back with more videos. maybe videos on React or Angular !

    • @Techsithtube
      @Techsithtube  8 ปีที่แล้ว +1

      I do have a plan to create react video in next few months. Keep an eye on it

  • @eqdatshit8406
    @eqdatshit8406 6 ปีที่แล้ว

    That life array tho

  • @kavyashribj
    @kavyashribj 5 ปีที่แล้ว

    Haha that example: ['born',' learn to walk', 'learn js' ...dowhatever, 'go to heaven'] :'D

  • @anshul123bisht
    @anshul123bisht 8 ปีที่แล้ว

    var x=function(){
    console.log(arguments[0]);
    };
    x(1,2,3); this will give o/p=>1 how is this possible if arguments is not an array ??

    • @Techsithtube
      @Techsithtube  8 ปีที่แล้ว

      Its an array like object but not array. if you do typeof(arguments) would not give you array

    • @anshul123bisht
      @anshul123bisht 8 ปีที่แล้ว

      thnx ,man keep up the good work for the ones in need :)

  • @seenuvasanv
    @seenuvasanv 7 ปีที่แล้ว

    Thanks

  • @abhishekkhandare4872
    @abhishekkhandare4872 6 ปีที่แล้ว

    Array.prototype.push.apply(a,arr2)
    I don't getting this line sir
    😥

    • @bhanubaghel3012
      @bhanubaghel3012 5 ปีที่แล้ว

      this is just same as pushing every element of (arr2) to the (a) array if you have to do this just use ( a.push(...arr2); ) This is same as
      ( Array.prototype.push.apply(a,arr2); )

  • @leelomchen3119
    @leelomchen3119 5 ปีที่แล้ว

    4′45″ ...so when you pass an argument using
    spread operator is called rest parameters.

  • @juho-pekkaropelinen5317
    @juho-pekkaropelinen5317 5 ปีที่แล้ว

    var a = [1, 2, 3];
    var b = [4, 5, 6];
    What's the difference between
    a.push(...b);
    a.concat(b);
    a.concat(...b);
    The output in two last ones is [1, 2, 3, 4, 5, 6, 4, 5, 6]. Could someone please explain why?

    • @Techsithtube
      @Techsithtube  5 ปีที่แล้ว

      you pushed twice on that is why you have entries twice.

  • @flamingobird8513
    @flamingobird8513 6 ปีที่แล้ว

    var n = [11,12,13];
    var n1 = function(a,b,c, ...n){
    console.log(arguments);
    };
    console.log(n1(1,2,4));
    Answer : { '0': 1, '1': 2, '2': 4 } // why 11,12 and 13 are not in the n1's arguments

  • @shapanization
    @shapanization 8 ปีที่แล้ว

    Noice!!!

  • @Octopie18
    @Octopie18 8 ปีที่แล้ว

    When turnings the array like object of 'arguments' into an array, you can simply do:
    let args = Array.from(arguments);
    for simplicity sake instead of the Array.prototype.slice.call funkiness.
    Also you should be using 'let' and 'const' instead of 'var' for declaring variables.

    • @Techsithtube
      @Techsithtube  8 ปีที่แล้ว

      +Nick yes var should not be used . thanks.

  • @kamdroid
    @kamdroid 8 ปีที่แล้ว

    My parameters are better than the rest ;)

    • @Techsithtube
      @Techsithtube  8 ปีที่แล้ว

      +Norema Nosini :) a good one mates!

  • @jain.sachin
    @jain.sachin 7 ปีที่แล้ว

    whatever you are trying to explain its really good but what happen to you expression and accent. :D

    • @Techsithtube
      @Techsithtube  7 ปีที่แล้ว

      :) crazy thumbnail makes you do crazy things.

  • @punithaarockiaraj3411
    @punithaarockiaraj3411 4 ปีที่แล้ว

    Theivame....

  • @hatrick3117
    @hatrick3117 6 ปีที่แล้ว

    Damn, this guy could look like hes 20 whenever he want's!
    Anyway, wanna add that this dosen't work :
    function foo (a, ...n, b) {
    console.log(a);
    console.log(b);
    }
    foo(1,2,3,4,5); // SyntaxError: Rest parameter must be last formal parameter :(

  • @Yeezybreezzy
    @Yeezybreezzy 4 ปีที่แล้ว +1

    this = ...cringe;

  • @JSM2910
    @JSM2910 8 ปีที่แล้ว

    never ever use that shirt again please.

    • @Techsithtube
      @Techsithtube  8 ปีที่แล้ว

      +Joakim Mohn Thanks . yes i wont use that shirt again. :) thanks for noticing .