Tutorial - 6
• Revision of yesterday lecture
• Create a mini project of a simple calculator
• Create a mini project of todo lis
• What is JSON
• Event loop
• Event loop examples
• callback-queue
• API
• async calls
• setTimeout
• fetch
• Promise
Event loop
• Any execution happening in JS is taken care of by its
property of being "single threaded synchronous
language"
• And in order to achieve that we have Execution
Context
• But sometimes we have scenarios of handling the
call back functions or promises where the
behaviour of EC is not regular in order to maintain
JS core value of single threaded + sync. language
• Just to achieve that we have something called Event
loop
• Lets look into the pictorial way where is location of JS
• Just to highlight one thing that browser instead of
just executing the JS code on client side it has many
other powers also and those powers are called as
Web API, like:
Example one
Example - 2
Example - 3
• Call back queue is formed by the call backs
• Micro task ques are formed by Promises &
mutation requestes on DOM
• Micro task queue has higher priority then call
back queue
• They both are entertained by event loop
existing between the call-stack and subsequent
queuing system
• Because of higher priority of micro tasks
queue over call back queue, it may sometime
may take really long for micro tasks queue to
finished hence it creates a "STARVATION"
situation in for call back queue
• https://www.youtube.com/watch?v=8aGhZQkoFbQ
API - Application programming Interface
• Application:
⚬ A call as a template (interface) to perform any operation is
called as API
• Programming:
⚬ API call is related to any particular operation or a
particular program
• Interface:
⚬ These calls are related to any particular endpoint with any
particular predefined template
Types of API: There are 2 major kinds of APIs now days
in market - REST API & GraphQL
• REST are bit heavy and have separate endpoints for
separate operation
• GraphQL is super lite and has only 1 endpoint called
"graphql"
• https://www.youtube.com/watch?v=PeAOEAmR0D0
Callback functions
• A function getting called up by another
function is called as call back function
Asynchronous calls
AJAX
AJAX uses XHR requests i.e. XMLHttpRequest
Promises
Different ways to handle the asynchronous calls
async-await
fetch-then

Web development basics (Part-5)

  • 1.
    Tutorial - 6 •Revision of yesterday lecture • Create a mini project of a simple calculator • Create a mini project of todo lis • What is JSON • Event loop • Event loop examples • callback-queue • API • async calls • setTimeout • fetch • Promise
  • 2.
    Event loop • Anyexecution happening in JS is taken care of by its property of being "single threaded synchronous language" • And in order to achieve that we have Execution Context • But sometimes we have scenarios of handling the call back functions or promises where the behaviour of EC is not regular in order to maintain JS core value of single threaded + sync. language
  • 3.
    • Just toachieve that we have something called Event loop • Lets look into the pictorial way where is location of JS
  • 4.
    • Just tohighlight one thing that browser instead of just executing the JS code on client side it has many other powers also and those powers are called as Web API, like:
  • 5.
  • 6.
  • 7.
  • 8.
    • Call backqueue is formed by the call backs • Micro task ques are formed by Promises & mutation requestes on DOM • Micro task queue has higher priority then call back queue • They both are entertained by event loop existing between the call-stack and subsequent queuing system
  • 9.
    • Because ofhigher priority of micro tasks queue over call back queue, it may sometime may take really long for micro tasks queue to finished hence it creates a "STARVATION" situation in for call back queue • https://www.youtube.com/watch?v=8aGhZQkoFbQ
  • 10.
    API - Applicationprogramming Interface • Application: ⚬ A call as a template (interface) to perform any operation is called as API • Programming: ⚬ API call is related to any particular operation or a particular program • Interface: ⚬ These calls are related to any particular endpoint with any particular predefined template
  • 12.
    Types of API:There are 2 major kinds of APIs now days in market - REST API & GraphQL • REST are bit heavy and have separate endpoints for separate operation • GraphQL is super lite and has only 1 endpoint called "graphql"
  • 13.
  • 14.
    Callback functions • Afunction getting called up by another function is called as call back function
  • 15.
  • 17.
    AJAX AJAX uses XHRrequests i.e. XMLHttpRequest
  • 18.
  • 20.
    Different ways tohandle the asynchronous calls async-await
  • 21.