In this article, you will understand what JavaScript is, and you will write your first JavaScript program. Also, you will understand how the v8 JavaScript engine works and so many others. Anyway, let’s get started.

Table Of Contents

JavaScript is a high-level programming or scripting language that can be used to build a web application. This means you can use it on the front end or in the back end.

What is JavaScript

As I mentioned before, JS is a high-level programming or scripting language based on the chrome v8 engine to interpret its source code.

In the past, JavaScript was working only on the client-side part but currently, it becomes working with the back-end through node.js.

Additionally, JavaScript supports APIs, which means application programming interface and document object model (DOM).

There are 98% of web applications are based on JavaScript because It is working as Just-in-Time (JIT) compilation.

The JavaScript is a dynamic prototype and object-oriented programming language which is supporting urgent programming style. Such as functional, classes, even-driven, and so many else.

In the next section, you will take an overview about the JavaScript history.

JavaScript History

Before getting started in the history overview, JavaScript is only one language and there is no any language else do its job, especially in the front-end stage. That’s all.

Before JavaScript, the web pages were only static pages and were lacking for the dynamic procedures. So they decided to develop a scripting language for the Netscape Navigator.

The Netscape team was thinking to collaborating with Sun Microsystems to use their Java Programming language with Netscape tool. But that was failed for some unknown reasons.

They decided to hiring someone else to do this task, he called Brendan Eich, and let me say, that was the greatest decision ever made in the history.

Brendan Eich was started the task and generated the first version of the scripting language in 1995 and embedded it into the Netscape version 2.

Live Script

The language syntaxes were the similar syntaxes of Java programming language, and its interpreter was called a “LiveScript”.

Eich was thinking of The name for his new scripting language. In this time the Java was in a hot demand and its popularity was officially in spread. So he named his new scripting language with JavaScript name. And that was for a marketing ploy.

JScript

Microsoft takes over to generate its new Internet Explorer browser and that to start a new war for browsers, against Netscape Navigator company.

Microsoft team released their scripting language in 1996 to embed it with the Internet Explorer, they named it “JScript”.

This version was supporting HTML markups and CSS.

During this period, the most of the developers weren’t able to develop their websites in two browsers to be the same design in both. It was a big different change in design and structures of two both.

So, this point leads Netscape and Microsoft to create other attractive sentences and slogans to do a ploy marketing for each other.

Netscape used this slogan “best viewed in Netscape”, while the Microsoft used “best viewed in Internet Explorer”.

ECMA Script

To finish the slogan war. The Netscape company created a standard specification for the first ECMAScript language, and that was in 1997.

During several years, they released many versions from the ECMAScript language each year with a new version started from 1998 and ended in 2000 with this name ECMAScript 4.

But Microsoft was not standing idly because its Internet Explorer was in spread. They reached for 95% from the market.

That means the Microsoft JScript became as the standard specification for the client side of the web application.

In 2000 the ECMAScript has been stopped with the version 4. Because the JScript became more popular than ECMAScript, so Microsoft won.

ECMA Script and Macromedia

In 2004, Mozilla continued the challenge and released their new browser called “Firefox”, they improved this browser with ECMAScript 4 of the Netscape Navigator and did many other features according to the ECMA International standard.

This browser started to spread, and it became challenging Google company and Microsoft.

V8 JavaScript Engine

In 2008 Google started a new challenge and released Google Chrome browser with its v8 JavaScript engine. This browser was faster than Google Chrome competitors. Because they were dependent on just-in-time compilation.

In the next section, we will focus on the V8 JavaScript engine of Chrome browser. Let’s dive right in.

How the V8 JavaScript Engine Works

V8 engine is a Google project which is an open source created to do a high performance for the JavaScript programming language.

The V8 engine is written in C++ programming language implements with two phases which are ECMAScript and WebAssembly.

Additionally, the v8 engine works with major of operating systems such as Windows, macOS, Linux, and so many others.

Anyway, the mission of the V8 JavaScript engine is to translate the source code into binary bits (the machine code). And here, we are going to cover these phases. But before getting started, you have to know the difference between compiler and Interpreter.

The Lexical Tokens

The first step, is receiving the source code from the server. And then it starts to analyze it according to some instructions in the lexical analysis and then generates a string contains sequence of Lexical Tokens. This phase also called as a scanner.

The Parser

The parser is receiving the sequence of tokens and generates the Abstract Syntax Tree (AST) which is representing those tokens in a big structure.

The Interpreter

Once it receives the AST, the Ignition interpreter starts to generate the bytecode and that was produced from the AST.

Then it sends bytcodes to TurboFan, and here the TurboFan is converting these bytcodes into binary bits which is the machine code.

On the other hand, the V8 engine has another thing called Just-In-Time compiler to convert ECMAScript into native machine code and that before the execution.

The compiled code is another optimization or (re-optimized) to be a highly optimized binary bits or machine code.

If there are incorrect things happening during this stage. It de-optimize it and returns it to the interpreter to re-evaluate.

That was an overview of the V8 JavaScript engine work from the top. In the next section, I am going to write a program with JavaScript. Only to show a small box with – “Hello World !” message.

Write your First Program with JavaScript

Firstly, you have to install any editor to allow you to write the JavaScript code. And then copy the below code. Then open it in the browser.

<!DOCTYPE html>
<html>
  <head></head>
  <body>
    <script type="text/javascript">
      alert( "Hello World!" );
    </script>
  </body>
</html>

The result would be a popup box contains the – “Hello World !” message.

Wrapping Up

In this article, you understood what is JavaScript. And wrote a small program. Also, you have an overview about the history and more about the V8 JavaScript engine and how it does work.

Thank you for reading.