Core Flashcards
(36 cards)
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.
What is the behavior of Call Back function?
Callback functions and event handers are first stored in Web API environment and then transfer to Callback Queue
What is the behavior of Promises?
Promises are stored in API environment and then transfered to Microtask Queue (priority queue)
What is Starvation?
Too many micro tasks in the queue are blocking to call back queue excecute
What does Parsing do in Js?
Parsing breaks code into tokens and convert it into AST (Abstract Syntax Tree)
Is Javascript an interpreter or a compiler language?
Both. Follows JIT compilation. It interpretes while optimizing as much as it can.
Arrow Functions vs Regular Functions
- No argument object in arrow function
- Arrow functions do not create their own this binding
- Arrow functions cannot be used as constructors
- Arrow functions cannot be declared
- Arrow functions cannot be accessed before initialization
- Arrow functions when uses as a class methods bind to the class
- Arrow function resolve this lexicaly
What is Binding
Binding is the process to assign an object to the ‘this’ keyword when a function is execute.
What types of Binding exists?
- Default (direct invocation)
- Explicit (indirect invocation)
- Implicit (method invocation)
- New (object instantiation)
- Lexical (arrow function)
What does call() do?
Call a function using another context (this)