Debouncing in JavaScript | Frontend Interview Question ⭐

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

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

  • @TechnicalSuneja
    @TechnicalSuneja  2 ปีที่แล้ว +27

    Guys , setTimeout should be stored in timer variable. (Sorry , it was missed by me ) 🙂
    Please find the correct code as given below.
    let counter=0;
    function getData(){
    console.log("fetching Data"+counter++)
    }
    function myDebounce(call,d){
    let timer;
    return function(...args){
    if(timer) clearTimeout(timer);
    timer=setTimeout(() => {
    call();
    }, d);
    }
    }
    const BetterFunction=myDebounce(getData,1000);

    • @humtohchutiyehai1016
      @humtohchutiyehai1016 2 ปีที่แล้ว +1

      Thanks 💖
      Debouncing:-kitni bhi baar call Karo current call ko manega(purani calls ignored)Orr ek fixed time ke baad he current call execute karega.
      Throttling:-call karega per fixed intervals per jb tk Purani call Puri nahi hoti new call nahi karega.
      Correct?

    • @amitkrgupta094
      @amitkrgupta094 2 หลายเดือนก่อน

      ek aur improvment: args paas kr rahe ho retruning fn ko but not to callback.

  • @TechnicalSuneja
    @TechnicalSuneja  2 ปีที่แล้ว +5

    00:00 - Don't skip anything 🙏
    Aur kya haal sabke?
    btao next topic JS kon sa hona chahiye ??

    • @techpro338
      @techpro338 2 ปีที่แล้ว +3

      Sir video on DOM

    • @n-a-y-a-n
      @n-a-y-a-n 2 ปีที่แล้ว +1

      Using Namespaces to Prevent Conflicts

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

      How Play with data sending and receiving on server. And fully understand JSON concept please sir

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

      Video on react js

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

      Video on Dom
      I know Dom but want details videos

  • @viv_tried_coding
    @viv_tried_coding 2 ปีที่แล้ว +3

    I had made project last week on denounce and after watching your video i feel why i waste so much time to learni it u just rock in 10 min and its takes me 3 hour to learn.... Great suneja bhaiya

  • @gnanavelpandian7756
    @gnanavelpandian7756 2 ปีที่แล้ว +27

    I think setTimeout should be stored in timer variable.

    • @TechnicalSuneja
      @TechnicalSuneja  2 ปีที่แล้ว +9

      Yes , you are right ❣️ it was Missed by me 🙂

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

      @@TechnicalSuneja and you explained debouncing , by clearing the timeout even without initializing it , got 39k views , waah bc

    • @amitkrgupta094
      @amitkrgupta094 2 หลายเดือนก่อน

      @@sanchitbatra4431 thanks bhai. Tumhare karam meri ek interview bach gi.

    • @sanchitbatra4431
      @sanchitbatra4431 2 หลายเดือนก่อน

      @@amitkrgupta094 For better content on interview preperation , I have started my Low Level Design playlist , please take a look
      youtube.com/@nerdswhocode?si=c-TartdZ_5QZFwZ_

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

    I see lots of videos but you teacheed us in better and simple way

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

    i think this can write in better way also


    let counter = 0 ;
    let getData = (e) => {
    console.log('Fetch Data .... ', ++counter);
    };
    const doSomeMagic = function (fn,d){
    let timer ;
    return function(...args){
    clearTimeout(timer);
    timer=setTimeout(()=>{
    fn();
    },d);
    }
    }
    const betterFunction = doSomeMagic(getData,1000);

    • @PIYUSH-lz1zq
      @PIYUSH-lz1zq 2 ปีที่แล้ว

      bhai doubt hai ,,, isme timer increment kaise horaha hai ???

  • @AshutoshSingh-ym9vi
    @AshutoshSingh-ym9vi 3 หลายเดือนก่อน

    way of teaching is wonderful👍

  • @ananddwivedi1334
    @ananddwivedi1334 10 หลายเดือนก่อน

    aap bhut hi accha smjhaate ho....achcha smjh me aata hai.....❤❤❤❤

  • @ankushladani496
    @ankushladani496 2 ปีที่แล้ว +1

    Maja aa gaya bhaiya....🤘🤘🤘💥💥

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

    Sir your channel will grow at 1m+ because very helpful and useful content for new and intermediate developer

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

      Thanks a ton :-)

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

      @@ahn360 yes bro you can get job but usually it's good to know some intermediate D's for frontend role or some small company don't care they can give you with just html CSS js react but for big company I itself learning D's to crack faang company interview

  • @yashrao5132
    @yashrao5132 2 ปีที่แล้ว +1

    ha bro ! ye video totally ek fresher he dekh rha h hahah .. ye likhte hue mujhe ek cheej se or saamna krna pda .. hsne k liye laptop keyboard me ek bhi emoji nhi mila ... thodi der dimaag ldaane k baad screen pe .. emoji section ka logo mila ... to lo ab hss leta hu meri kaamiyabi pe 😄😄😂

  • @deepadasmahapatra18
    @deepadasmahapatra18 2 ปีที่แล้ว +1

    Your way of explaining is awesome..I am 35 and have started leaning Front-End end and tons of Thanks for your video

  • @sagar59
    @sagar59 8 หลายเดือนก่อน

    wonderful explanation

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

    Fentastic bhai ☺️💫

    • @PIYUSH-lz1zq
      @PIYUSH-lz1zq 2 ปีที่แล้ว

      bhai doubt hai ,,, isme timer increment kaise horaha hai ???

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

    onchange trigger when we submit the input or click mouse outside the input box, instead of onchange you should have use keyup event

  • @rajusheoran4
    @rajusheoran4 2 ปีที่แล้ว +1

    Great Work Sir 🔥🔥🔥

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

    sir your videos are so awesome. i understand easy that u explain.. it is so good

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

    Thank you Ajay.
    We really appreciate your effort

  • @ArjunSingh-es2iw
    @ArjunSingh-es2iw 2 ปีที่แล้ว +1

    Cake wala expample kafi acha tha

  • @dipkrguchait2780
    @dipkrguchait2780 2 ปีที่แล้ว +1

    Da da ma aj se Java script sikna chalu koiya💁

  • @alishakamboj1767
    @alishakamboj1767 3 หลายเดือนก่อน

    thank you 😄😄

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

    Thanks bhaiya❣️🙌

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

    Wait is over finally 😅😅Thanks for the video on this topic bhaiya . Your way of teaching is amazing

  • @getsetalk
    @getsetalk 2 ปีที่แล้ว +1

    Really helpful 👍🏻

  • @codlover1468
    @codlover1468 2 ปีที่แล้ว +1

    Best teacher 👍

  • @uditchikar716
    @uditchikar716 2 ปีที่แล้ว +1

    Sir temporal dead zone in JavaScript ke baare m koi video bnao

  • @ayushagarwal1584
    @ayushagarwal1584 7 หลายเดือนก่อน

    well explained, I got it now Thanks Sir 🫡

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

    @technical suneja first of thanks for this effort.
    aap ka onchange and onkeyup dono different ways me kaam kar raha hain. Onkeyup har ek key pe timeout function trigger ho raha hain jo ki galat hain.
    1) aap pehele ye bolo ki dono ka difference yesa ku hain?
    2)it will be better agar aap code pe debugger ya fir console.log laga ke onkeyup pe samjhao ki har ek keype keyse kaam kar raha hain?

    • @TechnicalSuneja
      @TechnicalSuneja  2 ปีที่แล้ว +1

      No worries
      Mn next video me difference bhi bta dunga 🤞👍

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

      @@TechnicalSuneja and vaiya ye bhi please bol dena ki onkeyup pe kua nehi kaam kar raha hain?

  • @hamzaakbar5321
    @hamzaakbar5321 2 ปีที่แล้ว +1

    Good

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

    Amazing video please continue regular series 👍🏻

  • @SaqibKhan-cc5um
    @SaqibKhan-cc5um 2 ปีที่แล้ว +1

    Backend par bhi Lao aik video

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

    thanks guruji❤

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

    sir, your teaching style is good but voice come little slow so please increase voice so we can hear video in noise environment

  • @AkashSingh-xf6bd
    @AkashSingh-xf6bd 2 ปีที่แล้ว

    Technical Suneja app bta skte hai ki is function m timer ki value sb set hogi or kha hogi ?

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

    //There is no need of unecessary closure and args parameter.
    let counter = 0;
    const logger = () => console.log('searching', counter++);
    let timer;
    const listener = () => {
    timer && clearTimeout(timer);
    timer = setTimeout(() => logger(), 500);
    };
    document.querySelector('input').addEventListener('keyup', listener);

  • @travelwithmansidev
    @travelwithmansidev 2 ปีที่แล้ว +1

    I believe the timer is not getting initialized in the code, this will lead to memory leaks, as you are calling settimeout on every second, but not clearing the timer. The code should have been timer = setTimeout(...)

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

      I was also thinking that and it work with timer=setTimeout

  • @dhanaraja2646
    @dhanaraja2646 2 ปีที่แล้ว +1

    What is the use of timer and args? U just calling function inside timeout thatst this half understanding for us will leads to problem.Please provide correct info

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

    Hii Bhaiya startup me jada development pe focus hota he ya cp pe

  • @S_A_videos-m5s
    @S_A_videos-m5s 10 หลายเดือนก่อน

    Angular series aaiye bhaiya

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

    Please continue dsa js series

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

    🙏🙏🙏🙏any body please reply what is the concept here for ... args , is it just a rest paramater or something more than that ??🙏🙏🙏🙏

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

    Bhaiya ji polyfill ke example krwao ek do

  • @rajivkumar2578
    @rajivkumar2578 11 หลายเดือนก่อน

    Nice bro

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

    Why you have used (...args)?

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

    Thanks

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

    Bhaiya ek confusion hai mern vs blockchain web3 developer kaha Jana sahi hai..mujhe thoda basic mern aata hai per mera mnn blockchain ka bhi hai per itna time nahi.And how much high can you earn as a mern stack developer.

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

    For those who are wondering how it is working even though the setTimeOut() in not stored in timer variable.
    First, that is not working as how it is supposed to. The function is being called every 1 Second but the timer is not being reset even though the user inputs another letter withing 1 Second. This is why input 'ajay' runs function 4 times giving 4 outputs. You can see this @12:24.
    Then he changes 'onkeyup' to 'onchange' which works differnet. But it seems now the input 'ajay' is giving only one output like it is supposed to @12:46. This is because 'onchange' doesn't call function on every input, instead it calls the function only when the user loses focus off the input element(meaning user clicking outside the element), after which the whole value of input is taken as a single input hence calling function only once and giving only one output.
    This is also a fine example of BUG because it seems that it is working fine which is not the case at all.

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

    Sir, why you are clicking outside the box as we don't need to focus out in flip cart?
    Is it really possible with onchange?

  • @1980ify
    @1980ify 2 ปีที่แล้ว

    Ajay, are you a front end dev or full stack?

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

    what is the use of ...args. YOu have never used it

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

    Super

    • @PIYUSH-lz1zq
      @PIYUSH-lz1zq 2 ปีที่แล้ว

      bhai doubt hai ,,, isme timer increment kaise horaha hai ???

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

    Can we directly use RXJS debounce operator, ?

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

    Your DSA JS series is superb and amazing and one of it's own kind.
    Humble request to plz add more to it (Linkedlist, Graphs, Tree, more searching and sorting)

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

    Timer variable ko to kuchh value hi assign nahi ki hai ...to vo if k andar kab jayega?

    • @TechnicalSuneja
      @TechnicalSuneja  2 ปีที่แล้ว +1

      First time wo nhi jayega :-) mane 3 times btaya hai iska reason video me please check again ..:-)

    • @ArunSharma-ij5pw
      @ArunSharma-ij5pw 2 ปีที่แล้ว +1

      But aapko timer = setTimeout karna hoga, warna har key press pe function call ho raha hai, it's just that wo 1 sec ke delay me ho raha hai, 4 separate call for a, aj, aja, ajay

    • @ArunSharma-ij5pw
      @ArunSharma-ij5pw 2 ปีที่แล้ว

      First time nahi jayega you are right, but jab timer ko value hi assign nahi ho rahi hai to wo next time b kaise jayega

  • @Swagger747-w7y
    @Swagger747-w7y 2 ปีที่แล้ว

    Sir agar starting me college k 4th year me 20lpa+ mile to 4-5 saal k experience k baad vo kitna hoga sir 40lpa+ hoga ky thik thak hi mehnat kr rhe hai job me aur ky vo 1cr+ jayega 10-15 years experience ya 20 years experience me pls pls pls pls pls sir

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

    sorry sir , but mujhe is code mein sab kuch sahi nhi lag raha kyunki fuction toh jitni bar app type kar rahein hai utni bar call ho raha hai phir api bhi bar bar call hogi par aisa nhi hona chahiye

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

    If someone wants to prepare for js, react with me... Can ping me... I just started preparing for front end profile.. And will be giving interviews in December.... Together we can prepare well..

  • @tashafkhan531
    @tashafkhan531 6 หลายเดือนก่อน

    Baccha be like: hey bhagwan kya julam hai 😂😂😂

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

    where is your angular tutorial

  • @MrK-nb7xr
    @MrK-nb7xr ปีที่แล้ว

    you did not assign setTimeout to timer ... please edit this video

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

    How got a web developers internship during graduation
    Pls make videos and I am in 3 sem hot to get a internship i know html css and Java script. is these skills enough for getting first job

    • @jagdishjena9058
      @jagdishjena9058 2 ปีที่แล้ว +1

      Yes you can get, but react.js kar lo

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

      @@jagdishjena9058 are you from odisha

  • @findforme9030
    @findforme9030 2 ปีที่แล้ว +1

    Sir where front end tuterial links.. .

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

    👍👍

    • @PIYUSH-lz1zq
      @PIYUSH-lz1zq 2 ปีที่แล้ว

      bhai doubt hai ,,, isme timer increment kaise horaha hai ???

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

    sir Naukri me profile toh banaya hein but calls nahi aa rahe hein, Kya karu?

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

    @pls see my comment why stopping dsa series sir

  • @coder_ishwar_kumar
    @coder_ishwar_kumar 2 ปีที่แล้ว +1

    what u wrote wasnt the concept of debouncing ...it is just creating delay..
    pls make a fresh video

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

    ❤️

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

    Why you used (...args) did not understand

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

    Iski playlist nhi mil rahi sir

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

    Sir please help me

  • @priyamchhabra3938
    @priyamchhabra3938 2 ปีที่แล้ว +1

    Akshay Saini video copied!!!

    • @TechnicalSuneja
      @TechnicalSuneja  2 ปีที่แล้ว +1

      Beta ji 😊 jaake match ker lo video.. TH-cam chord dunga agar aisa hua to .. kafi mehnat se content banata hun ❤️

    • @priyamchhabra3938
      @priyamchhabra3938 2 ปีที่แล้ว +1

      @@TechnicalSuneja udhar bhi variable ka naam same tha betters function i guess you both are referring to same source and wo bhi flipkart ka example de rhe the.I guess you both were referring same material,sorry my bad!!! Isme chodne wali baat kha se aa gyi 😂😂You both are awesome btw.

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

      agree .. !! akshay saini explained the same 2 years ago..

  • @Pransshhh
    @Pransshhh 11 หลายเดือนก่อน

    Sir ji ek baar achhe se padh k video banate