Javascript Hard Parts Flashcards

1
Q

What are 3 main parts of Javascript engine?

A
  • Thread of Execution
  • Memory/Variable Environment
  • Call Stack
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
  1. What does it mean that Javascript is Lexical or Static Scoping
A
  • All the data from that scope gets backpacked

* We bring the data with us from when the function was born to wherever it goes hidden in the backpack

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
  1. What does NEW Keyword do?
A
  • Creates empty object and assign to THIS
  • Has hidden property _proto _ “ dunderscore proto”
  • Create a function + Object combo
  • Automatically Returns the object to global memory
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
  1. Arrow Function
A
  • THIS is the same as where it was defined
  • Arrow function always get whatever the THIS Keyword context, that what it gets
  • Arrow function has implied return
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
  1. What is This?
A
  • This refers to the object to the left of the dot in that execution context. Ex: user1.increment()
  • If no dot, this defaults to the window object
  • Biggest Mistake is calling a function in a method and THIS is referring to Window
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
  1. What is Class?
A
  • It is Syntactical sugar.
  • There is a prototype chain that creates a link that allows the ability to look up the chain for code
  • This is similar to Object Oriented Programming and the concept of inheritance where knowledge is passed down but this is just a link to look up stuff
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
  1. The Cycle of Code Queues
A
  • Thread of Execution runs through each lines of code
  • The Event Loop checks Call Stack if it has anything to run then the global code
  • Then it checks the microtask queue ( Promise-deferred functions) , then Callback Queue
  • Event Loop prioritizes functions in the microtask queue over the callback queue
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
  1. What is Promises ?
A

• Promises are invoked when there is initiated background web browser work/functionality and a place to store data in Javscript memory
• There is a placeholder object on JavaScript
• Fetch creates a promise object ( that object contains value and hidden property) and also sets up network request in web browser feature
• OnFulfillment is the hidden property of Promises ( also onRejection)
• Promise objects will automatically trigger the attached function to run (w/ the input being the returned data)
• We will call THEN method upon completion. .THEN gets a function into the unfulfilled array (Then can be considered “Run Later” )
o Any code we want to run on the returned data must also be saved on the promise object
• Promises you that it would let you know when such browser functionalities end, exits and could also provide you a way to return values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
  1. What is Asynchronous Code?
A
  • Asynchronous Code means doing code out of order from when you saw it
  • There is web browser feature request and at the same time in JavaScript, it returns a Promise Object which acts as a placeholder object.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
  1. What is Thread of Execution?
A
  • Goes through the code line by line and runs/executes each line
  • When it reaches a function, it does not read the code unless the function is called and continues to next line
  • JavaScript is synchronous by default and is single threaded. This means that code cannot create new threads and run in parallel.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
  1. What is Closure?
A
  • Functions get a new memory every run/invocation
  • When a function gets called, we create a new live store of data (local memory/state) for that function’s execution context
  • When the function finishes executing, its local memory gets deleted except for the returned value
  • Local memory gets backpacked along with function
  • If our function could hold live data between executions, this would let our function have an associated cache/persistent memory
  • All the relevant data from local memory execution context is stored in that function.
  • Closure allows a function to have attached a permanent memory store data
  • Persistent Lexical Static Scope Reference Data AKA Backpack AKA Function’s Closure
How well did you know this?
1
Not at all
2
3
4
5
Perfectly