Foundation: Engines & Compilers Flashcards

1
Q

What is deno

A

Deno is a simple, modern and secure runtime for JavaScript and TypeScript that uses V8 JavaScript engine and the Rust programming language.

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

What is Global execution context?

A

The global execution context is the default or first execution context that is created by the JavaScript engine before any code is executed(i.e, when the file first loads in the browser). All the global code that is not inside a function or object will be executed inside this global execution context. Since JS engine is single threaded there will be only one global environment and there will be only one global execution context.

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

What is function execution context?

A

Whenever a function is invoked, the JavaScript engine creates a different type of Execution Context known as a Function Execution Context (FEC) within the Global Execution Context (GEC) to evaluate and execute the code within that function.

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

What is nodejs

A

Node.js is a server-side platform built on Chrome’s JavaScript runtime for easily building fast and scalable network applications. It is an event-based, non-blocking, asynchronous I/O runtime that uses Google’s V8 JavaScript engine and libuv library.

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

What is an event loop

A

An event loop is a core concept in asynchronous programming and is central to how JavaScript handles non-blocking operations. It’s a mechanism that allows JavaScript to execute code in a non-blocking and efficient manner, particularly in web browsers and Node.js environments.

Here’s a brief overview of how an event loop works:

  1. Event Queue: JavaScript maintains an event queue (also known as a message queue) where events like user input, network requests, or timers are placed when they occur.
  2. Execution Stack: JavaScript also has an execution stack (call stack) where function calls are stacked as they are executed.
  3. Event Loop: The event loop continuously checks the event queue while the execution stack is empty. When the stack is empty, it takes the first event from the queue and pushes it onto the stack for execution.
  4. Non-Blocking: If the event being processed involves a time-consuming operation, like an asynchronous function or a network request, it doesn’t block the entire program. Instead, the event loop moves on to the next event in the queue.
  5. Callback Functions: Asynchronous operations often involve callback functions. When an asynchronous task completes (e.g., a file is read or a network request finishes), its associated callback is placed in the event queue for later execution.
  6. Repeat: This process repeats indefinitely, allowing JavaScript to handle multiple concurrent tasks and respond to events as they occur without freezing the application.

In essence, the event loop enables JavaScript to manage concurrency by efficiently handling asynchronous operations and ensuring that the application remains responsive even when dealing with tasks that may take some time to complete.

This concept is fundamental to understanding how JavaScript handles events, timers, and asynchronous operations, making it a crucial part of web development and other environments where JavaScript is used.

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

What is V8 JavaScript engine

A

V8 is an open source high-performance JavaScript engine used by the Google Chrome browser, written in C++. It is also being used in the node.js project. It implements ECMAScript and WebAssembly, and runs on Windows 7 or later, macOS 10.12+, and Linux systems that use x64, IA-32, ARM, or MIPS processors. Note: It can run standalone, or can be embedded into any C++ application.

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

What is Javascript Engine?

A

A JavaScript engine is a software component that executes JavaScript code. The first JavaScript engines were mere interpreters, but all relevant modern engines use just-in-time compilation for improved performance

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

What is happening inside JS Engine?

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

What does Parser do in Javascript Engine?

A

It checks for syntax and semantics. Parser is nothing but a lexical analysis that results into the breaking of code into tokens in order to understand their meanings and these tokens gets converted into Abstract Syntax Tree(AST).

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

What is lexical analysis?

A

Lexical Analysis is the first phase of the compiler also known as a scanner. It converts the High level input program into a sequence of Tokens.

Tokens: A lexical token is a sequence of characters that can be treated as a unit in the grammar of the programming languages.

Example of tokens:
Type token (id, number, real, . . . )
Punctuation tokens (IF, void, return, . . . )
Alphabetic tokens (keywords)

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

What is Abstract Syntax tree?

A

It is a hierarchical tree like structure of program representation which allows interpreter to understand the program.
This AST is initially goes to the Interpreter.

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

What is Interperter?

A

It let’s the AST to get converted into Byte code.
In V8 engine, this process is known as Ignition but when some code gets repeated again and again.

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

What happens when you run?

A

In the above code, we are calling multiply() function 1000 times. When this code goes into the interpreter, the interpreter performance got decreased, since, Interpreter had to repeat this code again and again and then profiler will mark this code as warm and comes into action.

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

What is Profiler?

A

It will check for the repeating code that can be optimized. As soon as, it gets the repeating code, it basically moves the code into compiler.

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

What is compiler?

A

It spits out the most optimized byte code.

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

What is Turbo Fan?

A

In V8 Compiler is called TurboFan

17
Q

What is Ignition?

A

In V8, Interperter is called Ignition

18
Q

What is the First Javascript Engine?

A

Mozilla’s SpiderMonkey JavaScript Engine: SpiderMonkey is the first Engine created by Brendan Eich, Creator of JavaScript. He created this Engine at Netscape Communication in 1995 and now it is maintained by Mozilla Foundation.

19
Q

What is SpiderMonkey?

A

First Engine created by Brendan Eich, Creator of JavaScript.

20
Q

What is Typescript?

A

Typescript is a superset of Javascript that compiles down to Javascript.
Typescript primarily provides optional static typing, classes and interfaces.
TypeScript result in more robust software if used correctly.

21
Q

What is Babel?

A

Babel is a JavaScript compiler
Babel is a toolchain that is mainly used to convert ECMAScript 2015+ code into a backwards compatible version of JavaScript.

22
Q

What is WebAssembly

A

WebAssembly (abbreviated Wasm) is a binary instruction format for a stack-based virtual machine.

Basically which allows us to write web client-side using languages like Rust, C++ and Go.
Majorly used for Gaming and Figma is one application I use which runs on WebAssembly.

23
Q

What are the two places to store data for Javascript Engine?

A

Stack: It is a data structure used to store static data. Static data refers to data whose size is known by the engine during compile time.
Example: variables, references to objects

Heap: It is used to store objects and functions in JavaScript. The engine doesn’t allocate a fixed amount of memory. Instead, it allocates more space as required.
Example: object and functions.

23
Q

What are the two places to store data for Javascript Engine?

A

Stack: It is a data structure used to store static data. Static data refers to data whose size is known by the engine during compile time.
Example: variables, references to objects

Heap: It is used to store objects and functions in JavaScript. The engine doesn’t allocate a fixed amount of memory. Instead, it allocates more space as required.
Example: object and functions.