Throttling in Javascript | Walmart Frontend Interview Question

Поділитися
Вставка
  • Опубліковано 11 січ 2025

КОМЕНТАРІ • 228

  • @medamsaisirisha847
    @medamsaisirisha847 4 роки тому +66

    Had faced an interview question almost a year back to limit the network calls to API, now after watching your videos finally got the answer which I have been searching for, thanks to linkedin which brought me here to your channel. Explained it really well sir.

  • @MaylynnNg
    @MaylynnNg 4 роки тому +11

    This is FANTASTIC. Made it so simple and easy to understand. Been struggling reading articles for hours trying to get it, and you've done it in 20 minutes!!
    Thank you thank you thank you!!

  • @bonleofen
    @bonleofen 5 років тому +32

    Bro, start a patron page. You just nailed it in explaining.

  • @mayankkumawat8802
    @mayankkumawat8802 5 років тому +8

    highly underrated channel... keep doing the great job

  • @anonymous........
    @anonymous........ 4 місяці тому +1

    20:13 --> Here `apply` method takes an array of arguments. This can be useful when you don't know how many arguments will be passed to the function.

  • @Nikhilkumar-yh7yc
    @Nikhilkumar-yh7yc 3 роки тому +5

    In debouncing one , i was little confused but because of this one that video also got cleared .. the part i love in this video , You told us how to write it step by step .. A Infinite thanks.. Please cover many important topics in your Namaste JS series .. You are like a GOD for me in Frontend journey .. I know you are very busy .. but 1 lakh people is waiting for your next videos .. Please do .. A respect for U .. Akshay Sir -- A great tutor..

  • @bonleofen
    @bonleofen 5 років тому +6

    You deserve a genuine like and subscription. Thanks for the video.

  • @Nikhilkumar-yh7yc
    @Nikhilkumar-yh7yc 3 роки тому +2

    Akshay Saini - A Tutor for the people , who think they never be a good developer.. Last Year i started a journey for frontend deveolper. I got confusions in , Callback, this, call bind and apply, clousers , curring , scopes .. literally i was struggling . I came to your old series Core fundamental of JS. nd I was like what this guy wanted to tell . I didnt like you .. then after sometime i found your namaste JS nd i am confident in this all topics that i mentioned ... Now I m growing stronger day by day .. I m watching your old series nd i m getting it very clearly ..

  • @dhirajbhujade5108
    @dhirajbhujade5108 3 роки тому

    This channel is goldmine for JavaScript developers!

  • @sahilsatishkumar
    @sahilsatishkumar 4 роки тому +1

    0:00 Intro
    0:58 Context/Recap
    4:20 code (whiteboard)

  • @GhanshyamDobariya90
    @GhanshyamDobariya90 4 роки тому +8

    20:06 do you know why we used apply method . No I won’t tell you here.... Lol.... bro honestly every time I see your videos here... i fall in love in learning.. and yes style of your explanation is v good and easy...

    • @akshaymarch7
      @akshaymarch7  4 роки тому +1

      😅

    • @sachin__ak
      @sachin__ak 4 роки тому +1

      @@akshaymarch7 call also can be used, you just need to unpack the array(...args), apply is mostly not used after es6 released

  • @javidg4197
    @javidg4197 5 років тому +3

    bro, u just nailed it man . Expecting more videos from you. all the best

  • @bidishadas832
    @bidishadas832 3 роки тому +1

    A very well-explained video. You know, everyone explains the difference between throttling and debouncing. But writing a new throttle function is just a different level altogether.

  • @neocephei45
    @neocephei45 3 роки тому +1

    I dont usually comment but I'm gonna start doing it!
    Even if the video is old It help me quite a lot! I will have to rewatch a few times to deeply understand it to apply it to my code, but I understand the main idea.
    Thank you!

  • @akakiburjanadze2387
    @akakiburjanadze2387 5 місяців тому

    Dude your videos are simply amaizing! I have learned 10x more than that what I knew before and feel so much confident in my JavaScript knowledge. Big Thanks!

  • @02sonali
    @02sonali 4 роки тому

    This could not be explained in any better way. Superlike !!

  • @dhruvitgaloriya7358
    @dhruvitgaloriya7358 5 років тому +2

    I just say thank you Akshay for making such a good video and clear concept and doubts.This is first comment ever in UA-cam

  • @JavaScriptWithSohail
    @JavaScriptWithSohail 4 роки тому +20

    Awesome video!
    But I think there is no need to store the context and arguments in variables, it makes sense in the debounce but here we are not calling the function in setTimeout so we can directly use "this" and "arguments".

    • @mattwaala
      @mattwaala 2 роки тому

      yeah make sense :)

    • @jaishrikrishna5755
      @jaishrikrishna5755 2 роки тому

      can you explain why we use this and arguments when we call Settimeout

    • @Adam-nw1vy
      @Adam-nw1vy Рік тому +1

      ​@@jaishrikrishna5755 We use this to prevent losing the this context. The function throttle is meant to be reusable and able to take in any callback function, i.e. fn, which means that the callback can be something that looks like objectName.callback. So if we invoke throttle like this: throttle(objectName.callback, limit), then the this context will refer to objectName, which can cause many issues. To prevent that, we need to bind the "this" context to the inner function returned by throttle.
      For the arguments, we need to use them to pass along any arguments taken by the callback function.

  • @shanusaini945
    @shanusaini945 3 роки тому

    Great Video...
    15:20 for anyone who want to see the code.

  • @imranshaikh115
    @imranshaikh115 5 років тому +4

    Very good explanation akshay, may god filled you with a lot of knowledge. Thanks a lot for making us understand a complex concepts in an easy way, you made it simple and clear.

  • @Shahrukh-p2z
    @Shahrukh-p2z Рік тому

    Thank you so much for sharing your knowledge i learned so much from you no one taught me this even in my company

  • @159binny
    @159binny 2 роки тому

    These days interviewers are using the examples even given by you. One person asked me how do you limit Clicks in a game and the same story you described. What a revolution you have brought.

  • @ritsk4338
    @ritsk4338 5 років тому +1

    Awesome video... yesterday only I found your channel and now become a big fan. Very Informative videos. Thank alot.

  • @santoshkadam8431
    @santoshkadam8431 4 роки тому +4

    I'm regretting, why I couldn't find this channel before year or more.

  • @RavindraSingh-zg9eq
    @RavindraSingh-zg9eq 11 місяців тому

    what an explaination bhai amazing superb ,i have seen this code but i was asking myself why they r writing this line of code but u explained very clearly ,mostly i was having doubt with args but u explained veryy nice

  • @nitishgupta8393
    @nitishgupta8393 2 роки тому

    I have just watched a genius, you are gem man

  • @mayankkumar6091
    @mayankkumar6091 3 роки тому

    Debounce, Throttling and their difference, you have explained it excellently. Now we don't need to go anywhere else to study and understand them :). It is now all set in our mind.
    What I noticed is we need to include an extra return statement if flag is not true.. something like following If(!flag) return;
    Otherwise it will not throttle as intended because multiple setTimeout are going to be registered and they would mess up flag value.
    function throttleOne(fn, ms) {
    let flag = true;
    function wrapper(){
    if(!flag) return;
    if(flag){
    fn.apply(this, arguments);
    flag = false;
    }
    setTimeout(function(){
    flag = true;
    }, ms);
    }
    return wrapper;
    }
    let betterthrottleOne = throttleOne(expensive, 3000);

    • @DeepakGupta-zz1vf
      @DeepakGupta-zz1vf 3 роки тому

      Instead do this
      if(flag === true)
      {
      fn();
      flag = false;
      setTimeout(function () {
      flag = true;
      },limit);
      }
      This will not register more than once

  • @nonymousUser99
    @nonymousUser99 4 роки тому +1

    Really you make every topic easy by explaining it more clearly.... Nice!!!! 👍

  • @atwinedan9364
    @atwinedan9364 2 роки тому

    first time here and i couldnt resist to like and subscribe. thx man

  • @srikarkulakcherla2202
    @srikarkulakcherla2202 4 роки тому +2

    Bhai, I love you♥️😂
    Seriously man, learnt a lot from this playlist,thanks and keep posting more of this content...
    Would be nice if you made a video on this keyword

  • @rohitkudalkar92
    @rohitkudalkar92 4 роки тому +1

    feel very to found your channel. Love and support bhai.

  • @EpicKeyz
    @EpicKeyz 2 роки тому

    Greeeeeat explanation! I thought on how can I make "onresize" function calls more lightweight, that's where throttling comes. Thanks a lot for this video!

  • @ranjanprabhu789
    @ranjanprabhu789 4 роки тому

    Nice one. This will surely help a lot of people to understand js core better. Keep sharing more such videos. Thank you.

  • @jeckyanand717
    @jeckyanand717 3 роки тому

    Ashay... Great explanation with easy steps.
    Love to learn from you

  • @utkarshtripathi2349
    @utkarshtripathi2349 4 роки тому +2

    Very well explained, Thanx for publishing that much informative content.

    • @akshaymarch7
      @akshaymarch7  4 роки тому +1

      Glad it was helpful!

    • @sumanthchevula1601
      @sumanthchevula1601 9 місяців тому

      @@adityaagarwal2324 same doubt, did u get any answer for this?

  • @kashifalikhan4420
    @kashifalikhan4420 2 роки тому

    Awesome Explanation, Loved the way you explain the things

  • @pradeeplakshminarasimha8332
    @pradeeplakshminarasimha8332 5 років тому +1

    Your explanation is really good bro. Keep making more such videos.

  • @adityakalyani6668
    @adityakalyani6668 3 роки тому

    Do you know why we use apply here...??No I will not tell you here...... Dude tooo good, you yourself are laughing at that... I paused and laughed for a while thinking about those who haven't watched the earlier videos.!! Amazing videos and good humour

  • @SuperPowerHero
    @SuperPowerHero 5 років тому +3

    You're the best man!

  • @dheerajmantena6672
    @dheerajmantena6672 4 роки тому

    Amazing video by Akshay, thanks for being generous in sharing your knowledge that means a lot for the upcoming dev's....Keep going , sharing is caring...!!!!

  • @Hdsatija
    @Hdsatija 4 роки тому

    Great Explanations

    • @akshaymarch7
      @akshaymarch7  4 роки тому +6

      It will be coming up in Namaste JavaScript Series. Actually teaching Closures requires a little background knowledge for the audience. We'll move there definitely, but slowly.
      And trust me, I'm very desperate about covering that topic. I just love Closures. ❤️

    • @Hdsatija
      @Hdsatija 4 роки тому

      @@akshaymarch7 Thanks

  • @01binaryboy
    @01binaryboy 2 роки тому +1

    Thanks!

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

      Thank you so much for supporting my channel. This means a lot. ❤️

  • @AdnanAli-cp9hk
    @AdnanAli-cp9hk 7 місяців тому

    Awesome explanation Sir, thank you so much.

  • @0mb430
    @0mb430 4 роки тому +1

    onChange event of input control is great example for throttling

  • @manishapuri8419
    @manishapuri8419 3 роки тому

    your videos are really very detailed and easy to understand .. :) keep it up

  • @mohit0001ish
    @mohit0001ish 4 роки тому +1

    I really like your explanation!! Thumbs up, keep it up. :)

  • @PeaceUrSoul
    @PeaceUrSoul 4 роки тому +2

    Thanks Bro for sharing your knowledge, keep make more videos by selecting the topic and explain with example. Also please tell what challenges you face in coding on Uber projects. Thanks

  • @Flora-lc6qd
    @Flora-lc6qd 4 роки тому +1

    Best video explaination!!!!

  • @sachin__ak
    @sachin__ak 4 роки тому +1

    debounce executes on the last event fired(batch req) and throttle executes at starting(control flow)

  • @nikitabanthiya5846
    @nikitabanthiya5846 5 років тому +2

    Hey Akshay , Nicely done !! explained it properly .I'm liking your channel , can you answer more what they asked in Wallmart other than this ?

  • @ishmeetsingh4914
    @ishmeetsingh4914 2 роки тому +1

    Hi all, at the video time of 18:30 I have one query someone can please clear.
    When the throttle function will be called again, we are declaring and initialized the value of true again at its first line. Correct me if I am wrong, but I think the flag would never be false.

  • @adyraj9228
    @adyraj9228 5 років тому +2

    liked your approach bro. how desperately you want people to understand what you are saying... (y)

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

    Very clear explanation 👍🏻👍🏻👍🏻 thank you!

  • @aparupabanerjee9373
    @aparupabanerjee9373 4 роки тому +1

    You explain really well! Could you please make a separate video on Closure? Thank you so much for all the help! :) Good luck!

  • @pramodhjajala8021
    @pramodhjajala8021 4 роки тому

    Outstanding explanation from not an IIT ,NIT guy 😉

  • @rohangaonkar8912
    @rohangaonkar8912 3 роки тому

    Awesone video. just like to add that there may be cases where we would want to catch the last occurence of event. so with this we might miss last event so. we need one more closure var to account for that

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

    You are terrific.

  • @srikanthac9458
    @srikanthac9458 4 роки тому +1

    Man , your videos are so clear cut , just a suggestion do show it on the computer as well , maybe like using debugger or something , so that everyone can understand even better.

    • @akshaymarch7
      @akshaymarch7  4 роки тому +1

      Throttling is similar to Debouncing.
      I showed the demo in debouncing video, please go watch that then everything will be relatable. 😇

    • @srikanthac9458
      @srikanthac9458 4 роки тому

      @@akshaymarch7 oh okay cool

  • @Aman-Verma
    @Aman-Verma Рік тому +2

    Hi Akshay, very nicely explained. But there is one edge case that you missed. Could you explain a way to solve that.
    Edge case:-
    Suppose the delay is 1 sec. But if the user ends up typing within 1 sec. then I think this would cause issue, as the function would not be executed (even though the flag would be true but, to execute the function user needs to enter something but in this case he already entered before 1 sec i.e before setTimeout sets the flag to true)

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

      yeah. Thanks for raising this.I am also waiting for answers in this scenario and I think this handles mentioned scenario.
      function throttleOne(fn, ms) {
      let flag = true;
      function wrapper(){

      if(!flag) return;
      if(flag){
      fn.apply(this, arguments);
      flag = false;
      }
      setTimeout(function(){
      flag = true;
      }, ms);
      }
      return wrapper;
      }
      Got this from comments.

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

      When the user types for the first time, the event registered to keyup or keydown runs, and the registered function is called.
      1. As for the first time the flag is true, it enters the if condition and calls the function which contains the API call.
      2. After that in the next line we marked the flag as False and then the setTimeout function is called.
      3. The setTimeout() gets registered in the browser Web environment and waits for the timer(1 sec here) to expire.
      4. As soon as the timer is expired the setTimeout() body is executed and the flag is marked to true again.
      Note that if in between(before 1 sec expires) the user types- In this case, the event handler would call the throttle function, however, as the flag is set to false when it run last time, it would not enter the if condition and the function making API call is not executed. Even if the user types 100 characters in 1 sec.
      1. As soon as 1 sec expires the setTimeout would set the flag to true.
      2. When the user types for the 101st time, the throttle function would then call the function which would make an API call(or any other code as defined).
      Let me know if that works for you. Note that the lecture was in context to attain Throttling.

  • @banajittalukdar8236
    @banajittalukdar8236 4 роки тому

    Well explained sir, expecting more videos

  • @yeswanthh5068
    @yeswanthh5068 Рік тому +3

    I really miss the old akhsay😥😓

  • @jagrutiisantosh
    @jagrutiisantosh 4 роки тому

    Your JavaScript videos have always helped me. Could you make a video on interview questions for Full Stack JavaScript Developer.

  • @ashishnamdeo3620
    @ashishnamdeo3620 4 роки тому

    Really Bro. your video is awesome...... plz make another video like javascript DS & more on Js...

  • @FunOfHeuristic
    @FunOfHeuristic 5 років тому +1

    nice one bro, one small suggestion, please add cards or give the link of related video in the description.

  • @harshvarma3960
    @harshvarma3960 5 років тому +4

    ur beard look like "hellboy2"
    u cn take it as a compliment :

  • @soumyaranjanhota9338
    @soumyaranjanhota9338 5 років тому +1

    Awesome Video ...

  • @snehakamble229
    @snehakamble229 3 роки тому

    Very good explanation.

  • @lokeshlokesh-fx8le
    @lokeshlokesh-fx8le Рік тому

    In throttling, This flag method is easily understandable when compared to cleartimeout(timer) method.

  • @remysilvio
    @remysilvio 5 років тому +1

    Great video! You rock! I'm subscribed too!

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

    Akshay very good Thanks !!!

  • @alpacino3989
    @alpacino3989 4 роки тому

    Amazing concept!

  • @amitk0277
    @amitk0277 5 років тому +4

    Pls make tuts on web app optimization and interview questions

  • @manthananeja
    @manthananeja 4 роки тому

    munna bhaiya , garda mcha diye aap

  • @YallahYah
    @YallahYah 5 років тому +1

    Your videos are 🔥🔥🔥

  • @nehabhargava
    @nehabhargava 4 роки тому +1

    You made it so easy, a very nice explanation! Can you please also cover a video about Event emitters from scratch.

    • @akshaymarch7
      @akshaymarch7  4 роки тому +2

      Noted it down, Neha. Will try to cover that in future videos. Thank you for your input. ❤️

  • @ashimasingla5177
    @ashimasingla5177 3 роки тому

    Awesome Video!! Can you please explain other method also for thrashing using setTimeout because way you explain makes things really easy. Also can you please make a video on Walmart Interview Experience for UI developers.

  • @Alex-cc3ol
    @Alex-cc3ol 4 роки тому +1

    I would use clearTimeout instead of flag
    function throttle(callback, delay) {
    let timer;
    return function() {
    const context = this;
    const args = arguments;
    window.clearTimeout(timer);
    timer = window.setTimeout(() => callback.apply(context, args), delay);
    }
    }

    • @prateekbanga3074
      @prateekbanga3074 4 роки тому +2

      He used this technique to implement Debouncing but not throttling

    • @Alex-cc3ol
      @Alex-cc3ol 4 роки тому

      @@prateekbanga3074 yeah, I got that later

    • @abhijiths148
      @abhijiths148 3 роки тому

      Then that won't be throttling anymore

  • @_irrfan13_
    @_irrfan13_ 3 роки тому

    will throw a referenceError - can not access before initialization. thank you akshay !

  • @MrMaulikthaker
    @MrMaulikthaker 3 роки тому

    It's very simple UX nowadays is Put a loader when API call on btn click and stop loader after you got response or API failed. So user not able to click btn again and again

  • @devtest1814
    @devtest1814 4 роки тому

    Thanks !!! keep it up bro !!! :)

  • @ashokselvaraj8152
    @ashokselvaraj8152 4 роки тому +4

    Hey Yoo man akshay,
    I found a small bug in this code,
    if(flag)
    func.apply(context, arguments)
    else
    return;
    like this we need to use else case, otherwise we will face some issue while continuously trigger the same event some period of time.

    • @lenientliu6080
      @lenientliu6080 3 роки тому +1

      Yes, the return prevents generating extra setTimeouts.

    • @abhijiths148
      @abhijiths148 3 роки тому +1

      yes that's correct

  • @kushalchowdhury6296
    @kushalchowdhury6296 4 роки тому +7

    Hey, I have one confusion here, I've wrote the code, and it ran perfectly, but there's one thing that I didn't understand.
    Let's say, we pass a function and a limit in the throttle function. It sets the flag true, returns the function, sets the flag to false, then sets a timer, after which the flag is set to true, correct.
    but before the limit passes, if we click on the button again, and the throttle function gets called again, should it not set the flag to true again and run the function ?? Since setTimeout is an asynchronous function ??
    Please Reply

    • @harikrishnang33
      @harikrishnang33 4 роки тому

      Whenever throttle is called it sets the flag as true, is that your question? If it is, I'm also having the same question.

    • @ayushrajniwal
      @ayushrajniwal 4 роки тому +14

      Let me help!
      1. throttle function doesn't get called each time an event happens.
      2. Look at the code --> window.addEventListener("resize",betterFunction);
      3. Which means betterFunction will be called when an event fire🔥.
      4. throttle will return an anonymous function that will be assigned to betterFunction and that anonymous function will be called when an event trigger.
      betterFunction = throttle(); //

    • @juku1234
      @juku1234 2 роки тому

      For me, it works only until the first delay has ended. So, if the delay is 1000ms, it will call the function once in that time, but if you keep triggering the event, it will call the function every time, until i make a small pause, when it seems to reset it.
      if(flag)
      func.apply(context, arguments)
      else
      return;
      this fixes it

    • @mrimosorcar621
      @mrimosorcar621 2 роки тому

      @@ayushrajniwal Why does the anonymous function take place of throttle? The whole function should be called right?

    • @SumitSharma-ui7wx
      @SumitSharma-ui7wx 2 роки тому

      @@mrimosorcar621 no only returned function gets called

  • @jaisaram5239
    @jaisaram5239 5 років тому +2

    Please post video series on PWA

  • @official_roboGOD
    @official_roboGOD 3 роки тому

    Great video! One edge case that bothers me is that the last call made will not execute. Let's say I'm resizing a window then I would want the method to be called at the exact position where I stop.

  • @gokulsrinivasan8563
    @gokulsrinivasan8563 3 роки тому +2

    Hi Akshay, I have a question. you have initialized flag as true inside throttle function. When ever that function is called, flag will be true by default and the API will be made. I think you have to maintain flag as true outside throttle function.

    • @Aman-Verma
      @Aman-Verma 2 роки тому

      Actually throttle function is called only once. Therefore, flag will not be reinitialised again and again to true. And with the help of closures, the returned function will remember the value of flag. Hope i am clear

  • @susmitobhattacharyya1668
    @susmitobhattacharyya1668 2 роки тому

    What a content. But have a doubt that don't we need to clear the timeouts like we did in the debouncing?

  • @tanmay496
    @tanmay496 4 місяці тому

    Thanks it's now clear

  • @yusufmirkar6508
    @yusufmirkar6508 2 роки тому

    I dont think this context needs to be added here as func is not called inside setTimeout where intended this would be replaced with window reference. You have called func in same flow as context variable. this does not change for this flow.

  • @TheVR7
    @TheVR7 4 роки тому

    great video, i believe youtube live chats timeouts works on this principle, just guessing

  • @nitishkalra1995
    @nitishkalra1995 3 роки тому +1

    what happens if the setTimeout callback function (which sets flag to true) keeps waiting in the callback queue for its turn to come and meanwhile the time limit is completed. Referring to the Trust Issues with setTimeout video. Function which sets flag to true waits in the queue more than the limit time. What would we do in that case ?

  • @prateekchitransh1585
    @prateekchitransh1585 3 роки тому

    Awesome content. I am confused why didn't we use setInterval here.

  • @rushivani454
    @rushivani454 7 місяців тому +1

    Please do it in pc also after explaining it in board. So that we can see how it works and code is error free

  • @ranjithagowda9676
    @ranjithagowda9676 4 роки тому

    Great content.

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

    this is nice one, thanks, akshay what if we are hitting simultaneously sufficient number of request, does we need a lock mechanism, or is flag enough?

  • @vipulpathe9071
    @vipulpathe9071 3 роки тому +2

    How about using setInterval instead of setTimeout in this case? By the way, all your videos are really helpful! Thanks for efforts!! :)

    • @kunalthakur2974
      @kunalthakur2974 2 роки тому +2

      HI Vipul, Use setInterval and write a console line inside it , you will know. The setInterval will keep resetting the flag after the delay again and again.
      Reference :-
      function throttle(func, delay) {
      let flag = true;
      return function () {
      if (flag) {
      func();
      flag = false;
      setInterval(() => {
      flag = true;
      console.log(`${flag} is called from timer`);
      }, delay);
      } else {
      return;
      }
      };
      }
      const funct = () => {
      console.log("This call is Throttled");
      };
      let better = throttle(funct, 4000);
      better();
      better();
      better();
      setTimeout(better, 5000);

  • @gunasekart.j3552
    @gunasekart.j3552 5 років тому

    your explanation is good, I get more positive vibes after seeing your videos, keep doing your good work. I am currently a full stack developer who has a basic knowledge is javascript.....................I have a doubt in this video when user click the button continuously whether the throttle function is called multiple time or not ....or only the return function inside the throttle function is called....can u please explain if you have time..thanks in advance

  • @KevJaques
    @KevJaques 4 роки тому

    One of the first things to do is prevent further clicks by making the button idempotent!

  • @chillguyy.99
    @chillguyy.99 2 роки тому

    My implementation that i tried. hope it's also a valid example ?
    const throttle = (fn,delay)=>{
    let timer;
    return function(){
    if(timer===undefined || Date.now()-timer >= delay){ //timer will be undefined in the first function call
    fn();
    timer = Date.now();
    }
    }

  • @adithyabhat4770
    @adithyabhat4770 4 роки тому

    Thanks for the video!

  • @prikshit8
    @prikshit8 2 роки тому

    Amazing 🤩