Async - 401-advanced-javascript-Mai/amman-javascript-401d1 GitHub Wiki
Hoisting
normally in javascript variable and value are hoisted in the top of the code, in execution time it recognizes what written then so the variable and function definitions are at the top of their function.
The Call Stack :
the function is run in the top, once it executed it will be poped. once the function will be running at the time.
The Callback Queue
pass any results into the callback and enqueue the callback,(functions stored on a call back not executing they are waiting to but in other function that is in the call stack )
The Event Loop
push callback into the call stack if it's empty. situation:
- When the call stack pops its last function event loop checks call back if exists it push it into .
- When both the call stack and callback queue are empty event loop watch call back when it exists it push direct onto call stalk.
Javascript Callback Pattern:
- asynchronous method.
- doesn't let javascript wait to do it and tell it to keep work.
- error callback
Javascript Promise Pattern (promises):
- mange Asynchronous .
- execute some and move on.
.then()>> give data that can deal with (resolved)..catch()>> if rejected.
File System I/O
fs module gives ability to contact with file and operator (create, read, write, update,...)
Buffer
global built-in node js constructor. deal with data with the binary system.
Asynchronous Testing
- test via using the callback. (jest, mochajs).
Mock Testing_(fake info or data help to test the process)_ help in a test of the processing of data, not the availability of data.