Key points 1, 3, 4, 5, 6, 7, difficult points: 7 my JS code annotation only one/hour, that is, important knowledge points

one Five major browser kernels

The browser The kernel
IE trident
Chrome webkit blink
Safari webkit
FireFox gecko
Opera presto

The history of browsers and the birth of JS

In 1990 Tim Berners-Lee (a hypertext sharing fan) developed a world Wide Web port to C renamed libwww (later renamed Nexus). 2. In 1993, the University of Illinois NCSA organization (core member Mark Anderson) developed a browser meaning for MOSIAC: I can display pictures, In 1994 Mark Anderson and Jim Clark (SGI employees) formed MOSIAC Communication Corporation due to icon infringement (previously transferred to SPY by Tim Berners-Lee) It was renamed Netscape Communication Corporation, created Netscape Navigator and it was popular until around 2003, when Microsoft acquired Spy Glass in 1996, Internet Explorer 1.0 was born (the Trident kernel was modeled after the MOSICA kernel) and in 1996 Netscape engineer Brendan Eich created his own browser, Netscape Livescript (a precursor to JS) was developed on Navigator, and in 1996 JAVA caught on while Netscape’s livescript was lukewarm, so Netscape worked with Sun to promote the product together: Livescript changed its name to javascript 5.in 2001, IE6 XP was born. Due to the rise of JS, the JS engine was spun off into a separate JS engine. In 2003, Mozilla developed Firefox, Its core is based on Netscape Navigator (which was acquired by AOL in November 1998). Netscape opened its own kernel source code to disgust Microsoft. Microsoft copied the core of Netscape’s MOSIAC browser and created Internet Explorer, which eventually beat Netscape. Microsoft is true bad guys, but survival of the fittest, thanks to Netscape open source. In 2009, Oracle acquired Sun, and Js ownership was transferred to Oracle

Programming languages

Programming languages are divided into two categories: compile and explanation 1. The compilation type: write the source – > to through a compiler — — — — > > machine language executable file advantage: fast, after compiling can be executed directly do not need to compile again, and interpreted languages each run to translate is essential in the source faults: Compilations have cross-platform incompatibility issues, cross-platform needs to be recompiled, cross-platform porting is not very good. 2. Interpreted language: source code –> through the interpreter –> explain line execution line advantage: no need for different system platform porting music (each platform has a corresponding interpreter) Disadvantage: slower running

Scripting languages

PHP :JS client script :JS interpreter on the browser PHP: server script, PHP interpreter on the server The difference between back-end scripting languages and front-end scripting languages: Front-end scripts are visible in the browser check element, but back-end scripts are not

Five ECMAScript.

ECMAScript is a scripting language standardized by Ecma International (formerly the European Computer Manufacturers Association) through ECMA-262. This language is widely used on the World Wide Web and is often referred to as JavaScript or JScript, so it can be understood as a standard for JavaScript, but in fact the latter two (JavaScript, JScript) are implementations and extensions of the ECMA-262 standard.

ECMAScript syntax

(1) Single thread and multi-thread

Single thread: Can only do one thing

Multithreading: The ability to do more than one thing at a time

The JS engine is single threaded(Because js engines are single-threaded, JS is a single-threaded language)

The JS engine is single-threaded but can perform multiple operations at the same time, such as:The reason is that the Js engine is single threaded -> emulates multithreading

We will introduce a concept here:Rotation slice: a segment in which multiple tasks are performed in turn in a short period of time

Step (1) Task 1 and task 2 exist

(2) Split task 1 and Task 2 (cut them into many smaller tasks)

(3) Randomly arrange these task fragments to form a queue

(4) Send the task fragments into the JS process according to the queue order

(5) The Js thread executes one task fragment after another

(This is equivalent to having two tasks run for one millisecond and two tasks run for one millisecond.)

(2) JS reference

There are two ways to use a citation… external citation:

 <script type="text/javascript" src="js/index.js">  </script> 
Copy the code

··· Internal quotes:

 <script type="text/javascript">
    console.log("a");
    </script> 
Copy the code

Who do they refer to when they both exist?

In the figure below, which code do you think will be executed?

The answer is the code in the file “js/index.js”, even if the file does not exist. The reason is that js is an interpreted language (compiled line by line)

(3) variables

① Definition: a variable is a container for storing data. ② The process of variable declaration is composed of two parts: variable declaration (var (variable)) and variable assignment

var a;// Declare variables
a=3;// Variable assignment
Copy the code

Single declaration: A var declares multiple variables, for example:

  var  a,b;
Copy the code

③ Variable naming conventions

  • You can’t start with a number
  • Can start with a letter, underscore, or $
  • The value can contain digits, letters, underscores, and $
  • Do not use keyword and reserved word names (reserved words are reserved as keywords later)
  • Semantically named (to be meaningful, let others read understand), structured (such as Js_header, J-header specifically for JS)
  • Variable names are named in small camel case: lowercase first letter, uppercase first letter of each subsequent word

7. JavaScript values

1. Weakly typed languages

Dynamic languages -> are mostly scripting languages -> interpreted languages -> must be weakly typed languages static languages -> compiled languages -> strongly typed languages

Strongly typed languages: emphasize/enforce data types JS is weakly typed languages: weaken data types and automatically recognize data types (such as integers and floating points)

2. The original value

  • Number: contains both integer and floating point types
  • Boolean
  • String
  • Undefined: used to store variables that are not defined in JavaScript. For example, variables that have been declared but not assigned a value are of undefined type. The output of console.log() is also undefined
  • Null: an empty value

3. The reference value

  • Object: the object
  • Array: an array of
  • Function: the function
  • Date: the date
  • RegExp: regular

4. The difference between original and reference values

2. An object whose address is stored in the stack and whose value is stored in the heap, as in:

(1) Original value

Store a,b and assign:

var a=3; / Declare an A space, stored in a3
vara=b; / Declare a space b, copy the values of a into b a=1; / Open up a new space a(overlay1006) stored in new space A1
console.log(b);
Copy the code

B outputs a value of 3, which is different from a. If you want to change the value of the original value, you will create a new memory space for the assignment. The original memory space still exists in the stack memory.

(2) Reference value: address stored in stack memory, value stored in heap memory
var arr1=[1.2.3]; / Declare a space in stack memory, arr1, to store values in stack memory. The space in stack memory is to store addresses in heap memoryvararr2=arr1; / Declare a new space arr2 in stack memory, copy the stored ARR1 heap memory address to arR2 arR1.push (5); /arr1, the values arr2 points to together changeconsole.log(arr2);/ / output 1, 2, 3, 4, 5
Copy the code

Arr2 outputs the same value as ARr1 but when we reassign arR1, the value of arR2 is different from the value of ARr1

var arr1=[1.2.3]; / Declare a space in stack memory, arr1, to store values in stack memory. The space in stack memory is to store addresses in heap memoryvararr2=arr1; / Declare a new space in stack memory arr2, copy the stored arR1 memory address to arR2 arr=[1.2]; / Declare a new space arr1 in stack memory, and the value exists in the heap memory, store the new address in the space of the new ARR1, then call arr1 and arR2 to different addresses, so the value will be differentconsole.log(arr2);
Copy the code

Conclusion: it is not affected when adding value or modifying value