This is the first day of my participation in the August Challenge. For details, see:August is more challenging

Hello everyone, I am the prosperity of the other shore 🌸, a front-end 👨🏻💻 that firmly believes that hard work can change destiny. If I have the honor to write an article that can get your favor, I am very lucky ~

This series of articles was first published in nuggets

An introduction to the JavaScript language

JavaScript is first and first a programming language. It is a weakly typed, prototype-based, literal scripting language that runs on the JavaScript interpreter/engine. By script language, I mean that it does not have the ability to develop an operating system. Instead, write only “scripts” that control other large applications, such as browsers.

The JavaScript interpreter/engine was originally part of the core of the browser and was widely used to support client-side scripting languages (not just JavaScript), beginning with the running of HTML pages.

The JavaScript language itself doesn’t provide much of a core syntax that can only be used to do math and logic. For complex operations, such as I/O, JavaScript does not provide an API, but is provided by the host environment. There are two common host environments:

  • Server environment, also known as Node environment
  • Browser environment

The core syntax of JavaScript is relatively simple, consisting of only two parts: the basic syntax (such as operators, statements, and data types) and the standard library (which refers to objects with various functions such as Array, Date, Math, and so on). All other operations depend on the additional API provided by the host pipe to be used by JavaScript.

JavaScript’s past and present life

JavaScript was created in 1995 to replace some of the input validation that was previously the responsibility of server-side languages such as The Java language. But the history of JavaScript goes far beyond that, as shown below:

  • In 1992, Nombas developed ScriptEase, a scripting language for its CEnvi software, which could be embedded in web pages.
  • In 1995, Netscape developed another client-side scripting language, Livescript, for its Navigator2.0 browser. Later, as Netscape partnered with SUN, Netscape management wanted it to look like the Java language. So it was renamed JavaScript.
  • In 1996, Microsoft added JScript to Internet Explorer 3 in order to gain a technical advantage.To avoid copyright issues with JavaScript).
  • In 1997, JavaScript 1.1 was submitted as a draft to ECMA (European Computer Manufacturers Association), completed ECMA-262, which defines a scripting language standard called ECMAScript.
  • ECMAScript 2.0 was released in June 1998.
  • In December 1999, ECMAScript 3.0 was released, becoming the prevailing standard for JavaScript and becoming widely supported.
  • ECMAScript 5.0 was released in December 2009.
  • In June 2011, ECMAScript 5.1 was released and became an ISO international standard (ISO/IEC 16262:2011). By the end of 2012, all major browsers supported the full functionality of ECMAScript 5.1.
  • In June 2015, ECMAScript 6 was released and renamed “ECMAScript 2015”. After that, the plan is to release one version of ECMAScript per year, the next in 2016 as “ECMAScript 2016”, the next in 2017 as “ECMAScript 2017”, and so on.

Part of JavaScript

While JavaScript and ECMAScript are often grouped together, the JavaScript language is actually much more than ECMAScript. This is because JavaScript is an implementation of ECMAScript. The complete JavaScript language (browser) is actually made up of three parts, as follows:

  • ECMAScript: At the heart of the JavaScript language, it is the name of the scripting language standardized by ECMA-262.
  • DOM: Document Object Model (DOM) is a standard interface specification developed by the W3C.
  • BOM: Browser Object Model (BOM) provides a set of objects that can interact with the Browser window.

ECMAScript

ECMAScript is a language specification that contains syntax, types, statements, keywords, and operators.

Document Object Model (DOM)

DOM, short for Document Object Model, is an application programming interface for XML but extended for HTML.

The DOM maps the entire HTML page into a multi-layer node structure, in which each component of the HTML page is a node of some type.

The following sample code shows the source code for a simple HTML page:

<! DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta  name="viewport" content="width=device-width, Word-wrap: break-word! Important; word-wrap: break-word! Important; word-wrap: break-word! Important; "> <title> </title> </head> <body> <h1> </ HTML >Copy the code

The above code structure is automatically generated by VScode

DOM maps the above HTML page to a node structure like this:

Browser Object Model (BOM)

The BOM is also a shorthand for Browser Object Model, which is a collection of objects that allow developers to access and modify Browser Windows.

The BOM provides a set of objects that interact with the browser window, as follows:

  • Window object: represents the browser window. You can modify the size of the browser window and other functions.
  • Navigator object: This object provides detailed information about the current browser, including the browser name, browser version, current operating system information, and so on.
  • Screen object: Represents the current display and provides information such as the resolution of the user’s display.

The application of JavaScript

The original purpose of the JavaScript language was to run in the browser and perform some of the actions of input validation in the browser window. But so far, JavaScript has grown much more than that. The main applications of JavaScript are as follows:

  • It runs on a client, which is basically a Web browser.
  • It runs on the server side, which is basically the Node environment.
  • The Internet of things can be launched through domestic manufacturersRuff.jsTo implement.
  • Artificial intelligence can be developed through the TensorFlow framework provided by Google.
  • All kinds of applets, all kinds of popular client-side applets right now are written in JavaScript to write user scripts.
  • Database operations. Since the concept of a NoSQL database was invented, most NoSQL databases allow JavaScript to operate directly.

The advantage of JavaScript

The benefits of JavaScript can be summarized as follows:

  • It has the ability to manipulate the browser, which is the main role of JavaScript.
  • Has a wide range of applications, as we described earlier.
  • Performance is more powerful due to JavaScript syntax flexibility and the ability to be event-driven and non-blocking.

JavaScript runtime environment

There are two common runtime environments in JavaScript:

  • Independent Node runtime environment: Install a separate node.js on the running device. The installation is simple as follows:

    1. Open a browser, enter nodejs.org/en/ in the address box, and go to the node.js official website.
    2. Choose a suitable version
    • LTS version: This version is the long-term supported version of Node.js. This version is recommended!
    • Current version: This is the Current version of Node.js.
    1. After downloading, keep clicking next to complete the installation.
    2. Finally, open the command line/terminal tool to inputnode -vTo verify that the installation is successful. Print if the installation is successfulnode.jsVersion number of.
    3. Use it directlyNode Specifies the path of the JavaScript scriptCommand.
  • Each browser integrated environment, in fact, now the mainstream browser has supported JavaScript running environment, here recommended to use Chromium kernel browser, such as the latest version of the Edge browser and Chrome browser. The location for running JavaScript in the browser is developer Tools → Console

    The common way to access the [console] is as follows:

    • Direct access: PressCtrl + Shift + J
    • Developer Tools access: The developer tools shortcut is F12, orCtrl + Shift + I, and select the Console panel

Now we can run the following code:

function sayMe (name) { console.log('Hello ' + name); } sayMe(' The other side is busy ')Copy the code

conclusion

In this section, we mainly learn the following contents:

  • JavaScript is a weakly typed programming language, and the differences and history between JavaScript and ECMAScript.
  • The composite part of JavaScript.
  • JavaScript benefits applications and runtime environments.

We’ll look at the syntax of JavaScript in the next part