Core Flashcards

1
Q

Where does JS execute?

A

Execution Context

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does the parts of Execution Context?

A
  • Memory or Variable Envoriment
  • Code or Thread of Execution
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does Memory or Variable Envoriment does?

A

Allocate memory for all variables and functions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the initial value of memory for variables and functions?

A

Undefined for variables and the code inside the function for functions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What happens in the Code execution phase?

A

Variable assignation and create a new execution context for functions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What happen with an execution context when a partner function hit return keyword?

A

It’s deleted

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How does arrow function behave in memory phase?

A

As a Variable.
= undefined

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is Lexical Enviroment

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is Hoisting?

A

It’s the process to allocated memory space for all variables and function before code execution.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Are Let and Const Hoisted?

A

Yes, they are Hoisted but in other place that can’t be accessed before initialisation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a Block?

A
  • 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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is Closure

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is Garbage Collector

A

Javascript engine that frees memory when the variables or closure won’t be needed anymore

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a pure Function

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the Event Loop

A

Event loop continuosly observes Call Stack and when it is empty it transfer tasks to Call Stack.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the behavior of Call Back function?

A

Callback functions and event handers are first stored in Web API environment and then transfer to Callback Queue

17
Q

What is the behavior of Promises?

A

Promises are stored in API environment and then transfered to Microtask Queue (priority queue)

18
Q

What is Starvation?

A

Too many micro tasks in the queue are blocking to call back queue excecute

19
Q

What does Parsing do in Js?

A

Parsing breaks code into tokens and convert it into AST (Abstract Syntax Tree)

20
Q

Is Javascript an interpreter or a compiler language?

A

Both. Follows JIT compilation. It interpretes while optimizing as much as it can.

21
Q

Arrow Functions vs Regular Functions

A
  • 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
22
Q

What is Binding

A

Binding is the process to assign an object to the ‘this’ keyword when a function is execute.

23
Q

What types of Binding exists?

A
  • Default (direct invocation)
  • Explicit (indirect invocation)
  • Implicit (method invocation)
  • New (object instantiation)
  • Lexical (arrow function)
24
Q

What does call() do?

A

Call a function using another context (this)

25
Q

How do primitive values pass in Js?

A

By value: Primitive values: number, string, boolean, undefined, null, symbol

By reference: object, array, functions

26
Q

What is this?
Hello()

A

Function invocation expression

27
Q

What is this in a function invocation?

A

This is a reference to an Execution Context
This == window
This == undefined (strict mode)

This.method() == object

28
Q

Types of Functions

A
  • Function Declaration or Function Statment
    (function with name and hoisted)
  • Function Expression
    (const test = function () {}
    (Not Hoisted)
  • Arrow Function
29
Q

Design patterns

A
  • Singleton (allow only one instance of the object)
  • Prototype
  • Builder
30
Q

What is IIFE?

A

Inmeadiately Invoked Function Expression. It uses to create a private scoop for variables and not pulluting the global namespace

31
Q

What is functional programming in JavaScript

A

Pure functions, inmutability

32
Q

What is a promise?

A

An object or placeholder for a certain period of time until we receive the value from an asynchronous operation or fail.

33
Q

What does an async function return?

A

Always a promise.
* A promise inside an async function return the promise itself

34
Q

What is the difference between classic resolve promise and await?

A
  • Classic doesn’t await inside the function.
  • await awaits the promise resolve and continue the excecution
35
Q

What does fetch function returns?

A

A response with a body

36
Q

Where do setTimeout, events and promises and sync code are stored before go to the call stack?

A

SetTimeout: task queue or callback queue
Events: task queue or callback queue
Promises: micro task
Sync: call stack