JS Basics Flashcards

1
Q

What is JS Engine?

A

JS Engine executes the JS code. Chrome uses v8 engine. JS runtime consists of Stack and a heap. Teh stack is a place where the code executes and they store objects on the heap.

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

What is compilation and interpretation?

A

In compilation, entire source code is converted to a binary file and the file is executed. In Interpretation, the interpreter runs the source code line-by-line and runs the source code. JS is uses JIT where the source code is converted to machine code at once and runs it.

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

What are the steps involved in JIT compilation in JS?

A

First, JS parse the source code to AST then it will be compiled and then executed. However, for the first time, it will less optimised compilation. It will do the optimization in a loop many times.

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

How does the JS runtime looks?

A

The JS runtime consists of JS engine, web APIs and callback Queue. JS engine executes the code, browser provides Web APIs (in case of NodeJS this will thread pool) , and lastly, it has call back queue. The callback (such as setTimeout) will be in the callbaack queue and later moved to the stack.

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

What is a scope?

A

Scope is a region/environment where a certain variables can be accessed,

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

What are types of scope?

A

Global scope Function scope and Block scope (ES6) const and let are block scoped.

Variables declared in global scope are accessible everywhere

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

What is a scope chain?

A

When a function (2) is created inside function (1), function 2 can access all the variables of function 1. If function1 is having a if block then it cannot access const and let inside the if block because of the block level scope.

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

What is a execution context?

A

EC consists of variables, argument object and

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

What is hoisting?

A

Hoisting takes some types of variables to be accessible even before they are declared.

Function declarations are hoisted and their initial value will be the actual function. They are block scoped in strict mode; else it is function scoped.

var is hoisted but their value is undefined. They are function scoped.

Let and const and NOT hoisted. Their initial value is uninitialized./TDZ. They are block scoped.

arrow/function expression depends if let or var is used.

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

What is TDZ?

A

Temporal dead zone is a place where variable is declared later in the block but used before its declaration. The zone/code where it is used before its declaration is called TDZ. We get Reference error: cannot access error in TDZ. The reason of TDZ is that to avoid errors in the code.

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

Why hoisting?

A

It is mainly used to using functions declared using function declaration. Var is just a byproduct.

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

what is the difference between let and var?

A

Let is not hoisted; hence less bugs.
var creates a property in the window object.
Let is block scoped and var is function scoped.

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

What is a this keyword?

A

This keyword is a special variable that is created for every execution context/function.

For,
Methods - this will be the object

simple function call - this is undefined in strict mode. else it is window object.

arrow function - this will be surrounding function

Event listener - DOM object

Go through video #98

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