Javascript Essentials Flashcards
I know about the event loop IN BROWSER
Javascript engine is one engine inside of the browser. Everything that happens in the JS engine is synchronous. However other processes in the browser are asynchronous. Other than the callstack, there is another list that sits inside the JS engine called the Event Queue. This is a list full of events to listen for in the browser. The Event Queue is only looked at by the JS engine only after the call stack is empty. When an event happens that is in the Event Queue, the JS runs the function that was associated with that event being triggered. The browser is continuously looking at the Event Queue for events that occurred. When it sees an event it starts the process again.
I know what process.nextTick does
Defer the execution of a function until the next Event Loop Iteration.
The difference between setTimeout() and process.nextTick() is that the process.nextTick() function is specific to the Node.js Event Loop. setTimeout() uses JavaScript runtime to schedule its own queue of events. When using process.nextTick(), callback function associated with it runs immediately after events in the Event Queue are processed by the Event Loop in a single iteration. In comparison to setTimeout(), it is faster since queue associated with setTimeout() or the JavaScript runtime.
I know about the event loop IN NODE
The event loop is what allows Node.js to perform non-blocking I/O operations — despite the fact that JavaScript is single-threaded
I know what “let” does
let allows you to declare variables that are limited in scope to the block, statement, or expression on which it is used. This is unlike the var keyword, which defines a variable globally, or locally to an entire function regardless of block scope.
I know about closures and can find an example usage of it
Returning function B from function A. Function B has access to the same variable environment as A even though function A has executed and is popped off the call stack.
EXAMPLE:
creating function factories