Core Flashcards
Where does JS execute?
Execution Context
What does the parts of Execution Context?
- Memory or Variable Envoriment
- Code or Thread of Execution
What does Memory or Variable Envoriment does?
Allocate memory for all variables and functions
What is the initial value of memory for variables and functions?
Undefined for variables and the code inside the function for functions.
What happens in the Code execution phase?
Variable assignation and create a new execution context for functions
What happen with an execution context when a partner function hit return keyword?
It’s deleted
How does arrow function behave in memory phase?
As a Variable.
= undefined
What is Lexical Enviroment
Execution Context with a reference to Lexical Environment to it’s parent (think of it as a linked list node) Lexical it’s means herarky. Function C it’s Lexical setting inside B function.
What is Hoisting?
It’s the process to allocated memory space for all variables and function before code execution.
Are Let and Const Hoisted?
Yes, they are Hoisted but in other place that can’t be accessed before initialisation.
What is a Block?
- Code inside curly braces is called block.
- Multiple statements are grouped inside a block, so it can be written where JS expects single statement like if, for, while, etc.
- Values are stored inside separate memory than global. They are stored in Blocks. (let and Const are block scopes)
What is Closure
A combination of a function and it’s Lexical scope bundled together.
* Advantage data hidden and encapsulation.
* Disvantage may consume a lot of memory if garbage colecto didn’t work as expected
Const count = () => {
let counter = 0
return () => {
return counter++
}
}
const c = count()
c() //1
c() //2
What is Garbage Collector
Javascript engine that frees memory when the variables or closure won’t be needed anymore
What is a pure Function
Is a function that always return the same value if the same arguments are passed. It doesn’t depends of any state or data change
What is the Event Loop
Event loop continuosly observes Call Stack and when it is empty it transfer tasks to Call Stack.