JavaScript 101

Introduction

Key terms in Javascript and JavaScript engine

Contents

  1. JavaScript?
  2. JavaScript Engine with word definitions
  3. Call Stack and Memory Heap

1. JavaScript?

JavaScript (JS) is a lightweight, interpreted, or just-in-time compiled programming language with first-class functions. While it is most well-known as the scripting language for Web pages, many non-browser environments also use it, such as Node.jsApache CouchDB, and Adobe Acrobat

JavaScript is a programming language that adds interactivity to your website.

Learn more: https://developer.mozilla.org/en-US/docs/Web/JavaScript

The JavaScript engine and JavaScript is a single-threaded language that uses a callback queue.

2. JavaScript Engine with word definitions

V8 engine

V8 is Google’s open-source high-performance JavaScript and WebAssembly engine, written in C++. It is used in Chrome and in Node.js, among others. 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. V8 can run standalone or can be embedded into any C++ application.

Learn more: https://v8.dev/

Just In time Compiler

In computingjust-in-time (JITcompilation (also dynamic translation or run-time compilations)[1] is a way of executing computer code that involves compilation during execution of a program (at run time) rather than before execution.[2] This may consist of source code translation but is more commonly bytecode translation to machine code, which is then executed directly. A system implementing a JIT compiler typically continuously analyses the code being executed and identifies parts of the code where the speedup gained from compilation or recompilation would outweigh the overhead of compiling that code.

Learn more: https://en.wikipedia.org/wiki/Just-in-time_compilation

Interpreters and Compilers

An interpreter is that directly executes instructions are written in a programming or scripting language, without requiring them previously to have been compiled into a machine language program.

A Compiler is that translates computer code written in one programming language (the source language) into another language (the target language).

ECMA Script

ECMA script is the governing body of JavaScript that essentially decided how the language should be standardized for engine creators.

Example of Compilers

Bable is JavaScript compiler that takes your modern JS code and returns browser compatible JavaScript (older version).

TypeScript is a superset of JavaScript that compiles down to JavaScript.

  • Take one language and convert into a different one.

3. Call Stack and Memory Heap

In JavaScript engine, there are Call Stack and Memory Heap.

  • Call Stack: Where are in code in order
  • Memory Heap: A place to store and write

We need the memory heap as a place to store and write information.

With Call Stack, we need a place to keep track of we are in the code in order.

Every time, we run the code we use call stack. We can think of call stack as a region in memory that operates in first in last out mode.

function subThree(num) {
  return num - 3;
}
function calculate(num) {
  const sumTotal = num;
  return subThree(sumTotal);
}
calculate(5);

Call Stack [it run first in last out]

(anonymous)
calculate()
subThree()

Leave a Reply

Your email address will not be published.

ANOTE.DEV