From 9f1d92474769211a9f793bd9cfc216b556a94bd3 Mon Sep 17 00:00:00 2001 From: Akash <37179506+AkashSrinivasan@users.noreply.github.com> Date: Wed, 29 Jun 2022 00:36:50 +0530 Subject: [PATCH 1/2] Update 17-JSEngine-ChromeV8.md --- Notes/17-JSEngine-ChromeV8.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notes/17-JSEngine-ChromeV8.md b/Notes/17-JSEngine-ChromeV8.md index 4cf29ce..b80704e 100644 --- a/Notes/17-JSEngine-ChromeV8.md +++ b/Notes/17-JSEngine-ChromeV8.md @@ -15,7 +15,7 @@ to compile JS code. Interpreter : Takes code and executes line by line. Has no idea what will happen in next line. Very fast. Compiler : Code is compiled and an optimized version of same code is formed, and then executed. More efficient -- Code inside JSE passes through 3 steps : **Parsing, Compilation and Execution** +- Code inside JRE passes through 3 steps : **Parsing, Compilation and Execution** 1. **Parsing** - Code is broken down into tokens. In "let a = 7" -> let, a, =, 7 are all tokens. Also we have a **syntax parser** that takes code and converts it into an **AST (Abstract Syntax Tree)** which is a JSON with all key values like type, start, end, body etc (looks like package.json but for a line of code in JS. Kinda From 28350b6c185f0b6543163b974631ecf017f7cd38 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 28 Jun 2022 19:07:27 +0000 Subject: [PATCH 2/2] Restyled by prettier-markdown --- Notes/17-JSEngine-ChromeV8.md | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Notes/17-JSEngine-ChromeV8.md b/Notes/17-JSEngine-ChromeV8.md index b80704e..e717b1b 100644 --- a/Notes/17-JSEngine-ChromeV8.md +++ b/Notes/17-JSEngine-ChromeV8.md @@ -3,14 +3,14 @@ #### JS runs literally everywhere from smart watch to robots to browsers because of Javascript Runtime Environment (JRE) - JRE consists of a JS Engine (❤️ of JRE), set of APIs to connect with outside environment, event loop, Callback queue, Microtask queue etc. -- JRE is a container that can run JS code. +- JRE is a container that can run JS code. - ECMAScript is a governing body of JS. It has set of rules followed by all JS engines like Chakra(Edge), Spidermonkey(Firefox), v8(Chrome) -- JS Engine is **not a machine**. Its software written in low level languages (eg. C++) that takes in hi-level code in JS and spits out low level machine -code +- JS Engine is **not a machine**. Its software written in low level languages (eg. C++) that takes in hi-level code in JS and spits out low level machine + code In all languages, code is compiled either with **interpreter** or with **compiler**. JS used to have only interpreter in old times, but now has **both** -to compile JS code. +to compile JS code. Interpreter : Takes code and executes line by line. Has no idea what will happen in next line. Very fast. Compiler : Code is compiled and an optimized version of same code is formed, and then executed. More efficient @@ -18,16 +18,16 @@ Compiler : Code is compiled and an optimized version of same code is formed, and - Code inside JRE passes through 3 steps : **Parsing, Compilation and Execution** 1. **Parsing** - Code is broken down into tokens. In "let a = 7" -> let, a, =, 7 are all tokens. Also we have a **syntax parser** that takes code and converts it -into an **AST (Abstract Syntax Tree)** which is a JSON with all key values like type, start, end, body etc (looks like package.json but for a line of code in JS. Kinda -unimportant)(Check out astexplorer.net -> converts line of code into AST) + into an **AST (Abstract Syntax Tree)** which is a JSON with all key values like type, start, end, body etc (looks like package.json but for a line of code in JS. Kinda + unimportant)(Check out astexplorer.net -> converts line of code into AST) -2. **Compilation** - JS has something called **Just-in-time(JIT) Compilation - uses both interpreter & compiler**. Also compilation and execution both go hand in hand. -The AST from previous step goes to interpreter which converts hi-level code to byte code and moves to execeution. While interpreting, compiler also works hand in hand -to compile and form optimized code during runtime. +2. **Compilation** - JS has something called **Just-in-time(JIT) Compilation - uses both interpreter & compiler**. Also compilation and execution both go hand in hand. + The AST from previous step goes to interpreter which converts hi-level code to byte code and moves to execeution. While interpreting, compiler also works hand in hand + to compile and form optimized code during runtime. -3. **Execution** - Needs 2 components ie. Memory heap(place where all memory is stored) and Call Stack(same call stack from prev episodes). There is also a *garbage collector.* -It uses an algo called **Mark and Sweep**. +3. **Execution** - Needs 2 components ie. Memory heap(place where all memory is stored) and Call Stack(same call stack from prev episodes). There is also a _garbage collector._ + It uses an algo called **Mark and Sweep**. -Companies use different JS engines and each try to make theirs the best. +Companies use different JS engines and each try to make theirs the best. -- v8 of Google has Interpreter called *Ignition*, a compiler called *Turbo Fan* and garbage collector called *Orinoco* +- v8 of Google has Interpreter called _Ignition_, a compiler called _Turbo Fan_ and garbage collector called _Orinoco_