JavaScript – Introduction

Time:2021-5-8

1、 The origin of JavaScript

  1、In 1994, Netscape released navigator 0.9

It is the first mature web browser in history, but this version of browser can only be used for browsing, and does not have the ability to interact with visitors

2. Netscape had two options at the time:

Allow existing languages to be directly embedded in web pages (easy to promote, poor compatibility)

Invent a new language

3. In 1995, Sun company changed the name of oak language to Java, and officially launched it to the market, promising that this language can “write once, run anywhere”

4. Netscape, in alliance with sun, employs Brendan EICH, a 34 year old system programmer

Designated as the designer of this “simplified Java language”, in order to cope with the tasks arranged by the company, he designed JavaScript in only 10 days.

His design idea is as follows:

(1) Learn from the basic grammar of C language;

(2) The data type and memory management of Java language are used for reference;

(3) Using scheme language for reference, the function is promoted to the status of “first class”;

(4) Use for referenceSelf languageUsing the inheritance mechanism based on prototype.

Therefore, JavaScript language is actually a mixture of two language styles — (Simplified) functional programming + (Simplified) object-oriented programming. This was decided by Brendan EICH (functional programming) and Netscape (object-oriented programming).

2、 JavaScript usage

It is generally used to write client script to add interaction behavior for HTML pages. It is the foreground language, not the background language (except node. JS)

3、 Features of JavaScript

  1、Explain and execute (browser is interpreter): do not compile in advance, execute line by line, without strict variable declaration.

2. Easy to use: you can use any text editing tool to write, just need a browser to execute the program.

  3. Object based: built in a large number of ready-made objects, write a small number of programs to achieve the goal 

4JavaScript composition

1. ECMAScript: Syntax Standard for JavaScript. Including variables, expressions, operators, functions, if statements, for statements and so on.

2. Document object model (DOM): an API for manipulating elements on a web page. For example, let the box move, change color, rotate pictures, etc.

3. Browser object model (BOM) Broswer object model: an API for operating part of browser functions. For example, let the browser scroll automatically.

5The relationship between ECMAScript and JavaScript

In November 1996, Netscape, the creator of JavaScript, decided to submit JavaScript to ECMA, hoping that this language could become an international standard. Next year, ECMA released the first edition of standard document No. 262 (ecma-262), which stipulated the standard of browser scripting language, and called this language ECMAScript, which is version 1.0.

The standard was originally developed for JavaScript language, but it was not called JavaScript for two reasons. One is trademark. JavaScript itself has been registered as a trademark by Netscape. It is to show that ECMA, not Netscape, is the maker of the language, which is conducive to ensuring the development and neutrality of the language.

Therefore, the relationship between ECMAScript and JavaScript is that the former is the standard of the latter and the latter is an implementation of the former.

6、 The history of ECMAScript

particular year name describe
1997 ECMAScript 1 The first version
1998 ECMAScript 2 Version change
1999 ECMAScript 3

Add regular expression

Add try / catch

  ECMAScript 4 Not published
2009 ECMAScript 5

Add “strict mode” strict mode

Add JSON support

2011 ECMAScript 5.1 Version change
2015 ECMAScript 6(ES6) Add classes and modules
2016 ECMAScript 7

Increase exponent operator (* *)

Add array.prototype.includes

 

 

 

 

 

 

 

 

 

 

7、 JS is a weakly typed, dynamic language

#1. Weak type, strong type
According to the type system of computer language, it can be divided into strong type and weak type. The difference between the two lies in whether the implicit conversion between different types is transparent to users. From the user's point of view, if a language can implicitly convert all its types, its variables, expressions, etc. can be implicitly converted to get the correct type even if they are not of the correct type. For the user, it is just like all types can perform all operations. Such a language is called weak type

#2. Static language
Dynamic language: you do not need to specify a type when declaring a variable
Static language: the type must be specified before declaring a variable


#3. JavaScript is a kind of weak type and dynamic language, and the weak type is shown as follows

#2.1. The general rule is that the stronger the constraint, the less likely it is to make mistakes, but the more troublesome it is to write a program. In JavaScript, because the constraints are weak, this kind of error is easy to occur: the simplest example is:
 var a =200;


 var b ="1";


 var c= a + b;


You might expect C to be 201, but in fact it's "2001," which never happens in strongly typed languages. However, it is precisely because JavaScript does not have these constraints that it is easy to splice numeric and string types.

#2.2. Take the following example:
var a = '11';
a = a - '';
alert(typeof a);// -->number
"-" can be unary (negative) or binary (subtraction)

JS is a weakly typed language