This article has participated in the third “topic writing” track of the Denver Creators Training Camp. For details, check out: Digg Project | Creators Training Camp third is ongoing, “write” to make a personal impact.

Historical versions of JavaScript

While ECMAScript is an important standard, it is not the only part of JavaScript. In fact, a complete JavaScript implementation is made up of three different parts:

  • Core Model (ECMAScript)
  • Browser Object Model (BOM)
  • Document Object Model (DOM)

ECMAScript3 is the most widely used, because for browser support reasons, if the application needs to run on a lower version of the browser (IE9 (not included)), the production code must conform to ES3 syntax. If you leave out older browsers, you can develop using ES5 coding without the help of build tools. Compared with ES3, ES5 has many apis, such as Array map, filter, find, and findIndex. String trim, includes, function bing and other tool class methods are more convenient to develop. There are also canvas, document.querySelector, dom. ClassList and a series of DOM APIS…… , making development more efficient and convenient.

The release of ECMAScript6 brings the most transformative upgrade to the language. Here are a few examples to illustrate:

  • Let is added to declare the block-level scope, which makes up for the blank of JS function scope without block-level scope and avoids the phenomenon of var scope promotion.
  • The Class keyword has been introduced, which makes it easier to write a Class definition, even though it is just a syntactic sugar.
  • The Promise object, which provides a solution to asynchronous programming, avoids the problem of callback hell and more.

As well as new features such as Proxy and Reflect, JavaScript is moving closer to features in other high-level languages. Currently, with build tools such as WebPack, you can write ES6 in development mode and then release it to production in a lower version.

Javascript language features

  1. Interpreted scripting language: JavaScript is an interpreted scripting language. Unlike C, C++, Java and other languages, JavaScript is interpreted line by line during the running of a program.
  2. Object-oriented: JavaScript is an object-oriented scripting language that can not only create objects, but also use existing objects.
  3. Weak type: JavaScript language uses weak type variable type, does not make strict requirements on the data type used, is simple and flexible, but not convenient to maintain and debug.
  4. Single-threaded, event-driven: JavaScript is event-driven and can respond to user input without going through a Web server. When visiting a web page, JavaScript can directly respond to such events as clicking the mouse, moving the mouse up and down, or moving the window.
  5. Cross-platform: JavaScript is independent and can run on any platform as long as the Web browser supports it.
  6. Security: JavaScript is a secure language on the Web browser side. It doesn’t allow access to local disks or store data to the server; It is not allowed to modify or delete network text, and only information browsing or dynamic interaction can be realized through the browser. It effectively prevents data loss.

JavaScript compilation principle and execution

Take V8, the most advanced JS engine, as an example, and take a look at the principle and process of JavaScript compilation. The first step is to generate the AST from the JS source code. For high-level programming languages that are not understood by the interpreter and compiler, the first step is to turn it into something that both the interpreter and compiler can understand – the AST. There are two stages to generate an AST, namely lexical analysis and grammatical analysis. The first is lexical analysis: break down the lines of source code into tokens. Token is the smallest single character or string that is syntactically impossible to divide.

Once you have the AST and the execution context, the interpreter generates the bytecode from the AST and interprets the execution of the bytecode.