Three strategies for the JavaScript event loop - Brain Bytes [Java Brains]

แชร์
ฝัง
  • เผยแพร่เมื่อ 3 ก.ย. 2020
  • Learn about 3 strategies you can use in your JavaScript code to work with the event loop and the single application thread in JavaScript
    Java Brains website: javabrains.io
    #JavaBrains #BrainBytes #HowTo #JavaScript #Tutorial #Concept

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

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

    "The callback function gets put to the back of event queue". That's so refreshing!

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

    Happy Teachers Day !! One of the best teacher's !!!

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

    Best and the most hidden topic using JavaScript. Great Content

  • @CVenture
    @CVenture 3 ปีที่แล้ว +23

    Great .. Can you pls explain the differences between async await, promise and call backs? It confuses all the time..

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

      If we call a function inside another function then it is call called back.
      Promises are used to handle call back hells they have 2 parameters resolve, reject. To handle resolve we need to use .then to handle reject we need to use .catch
      To handle the promise chaining we will use async/await
      We need to use these async/await jointly
      for example
      async function test(){
      let data1=await func1();
      let data2=await func2();
      }
      async > promise > callback
      I hope you got some idea now

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

      @@ranikontham5573 Thanks for replying after 2 years tho. Appreciate your effort.

    • @d3vilscry666
      @d3vilscry666 5 หลายเดือนก่อน

      @@CVenture Do you understand it now? lol

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

    There are so many famous tutorials out there that teach wrong things.
    Your tutorials are the real thing ♥️.
    Please create a complete Javascript course.

  • @4t196
    @4t196 2 ปีที่แล้ว

    You explaine very well...

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

    So well-explained! Thank you!

  • @techiesrikanth2447
    @techiesrikanth2447 3 ปีที่แล้ว +4

    Happy Teacher's Day Koushik !!. Thanks for your Amazing Content.

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

    As usual you are great in explaining complex things in simple way...

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

    great examples; I learned a lot. Thx!

  • @MustafaAli-xj6lq
    @MustafaAli-xj6lq 2 ปีที่แล้ว

    Best and most simple video so far

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

    Great teacher always simplyfies the explanation like you

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

    Really liked the introduction to web workers. Quality content as always 🙏

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

    Great as usual.I learned a lot of java concept from you now I am learning Javascript advanced staff from you.I am grateful.

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

    Really Awesome, i always recommend ur channel to other people.

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

    Thank you Koushik for this great content

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

    I really like your didactic approach.

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

    Man this is gold!

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

    Thank you so much for such informative video 😊.. Please make playlist of Data structure and Algorithms using Javascript will feel more thankful. Because there is no such playlist to learn Algorithm using Javascript.Thank you 😊

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

    It's Great!!! Thanks a lot . You are amazing...

  • @FahadKhan-qj3ej
    @FahadKhan-qj3ej 2 ปีที่แล้ว

    Thank you so much.

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

    Please create tutorials for Docker and Kubernates, this topic is widely used and new !

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

    Awesome!!! Thanks.

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

    setTimeout(fn, 0) and setNextTick are effectively same right, appendig the function to end of pending function callback queue 🤔. Although for anyone reading there is a setImmediate 😐 which actually happens to place the function call for the next tick and not the end if event loop. 😌 Small nuances of nodejs api

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

    Great explanation, but I have some doubts: In strategy 1, why can't we just call the lessimportantWork() after the moreImportantWork()? why to use setTimeout altogether?

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

      hmm....good question AMC

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

      Js works in a loop. A good candidate would be user interaction and screen update functions. Not terribly important but needs to be small, quick and out of the way when* needed.
      Let’s say you’re updating a cart to a busy server, not an intensive process but can be slow. You still need to interact with the user and that all happens in the event loop.
      * when the loop magic allows time for them

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

    great!

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

    Hi Koushik, can web workers communicate amongst themselves? webWorker1 and webWorker2 for example

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

    Can you please tell us what software you are using to edit video.

  • @AnandKumar-ro1yd
    @AnandKumar-ro1yd 3 ปีที่แล้ว

    Sir, have you created multithreading and concurrency tutorial? Please create tutorial in this. These concepts are hard to understand

  • @enki1939
    @enki1939 9 หลายเดือนก่อน

    why do we not just move the lessImportantFunction after the moreImportantFunction? Feels like that would be more of an intuitive way that doing the setTimeout(fn,0)?

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

    Use case one. just reorder function call .no need for settineout

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

    Hello Sir, Please make one series on Nashorn JavaScript. The amount of contents on internet are very very less. Please address this. Thank You..!!

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

    I always used setTimeout with 0ms as the time, but only now do I properly understand what it's actually doing

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

    Can anybody tell me pls what is the bug in the 2nd method?

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

    So at the end is Nodejs a similar Java runtime ? since web workers were lunched ? at the end the difference between Java ecosystem and Javascript is only the fact that JS is a loosly typed, flexible language ?! It seems like there is a mimication or recreation or lets say highjacking of the Java ecosystem and a community revolution against Oracle passed supremacy, a community revolution supported by Google through v8 engin... ? is it right ?

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

      Is event loop concept also in javascript?

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

    9:26 when you explain strategy 2
    function processArray(bigArray, start)
    I think it will only execute once, because right after the forloop, start get increased by BATCH_SIZE while BATCH_SIZE remain the same the whole time

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

      He told that there is a bug in the code, the condition should have been "i < start + BATCH_SIZE" instead of "i < BATCH_SIZE"

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

      How it will be start + batch size? Batch size is the size of the array and loop can't exceed batch size.