In the JavaScript,

Major browsers

The browser The kernel
IE trident
chrome webkit=>blink(webkit)
safari webkit
firefox Gecko (gecko)
opera presto

Browser history and JS birth

  1. 1990
    1. Tim Berners-Lee is someone who shares information with hypertextworld wide webMigration toC libwww/neus Allow others to view websites written by others
    2. 1993
      1. University of Illinois NCSA blocks (Mark Anderson)MOSIAC browser from displaying images in graphical browsers
    3. 1994
      1. Mark Anderson and Jim Gilac silicon Valley SGI
      2. MOSIAC communication corporation
      3. Netscape Navigator ->2003
    4. 1996
      1. Microsoft buys Spy Glass
      2. IE internet exploror 1.0
      3. With IE 3 came Jscript, the first scripting language
      4. Brendan Eich at NETSCAPE
      5. Livescript was developed by NAVIGATOR
    5. 2008
      1. V8 engine
        1. Direct translation machine code
        2. Run independently of the browser

A programming language

  1. A compiled
    • Translation process: source -> compiler -> machine language -> executable
    • advantages
      • Fast running speed
    • disadvantages
      • Cross-platform requires recompilation
  2. interpreted
    • Translation process: source code -> interpreter -> explain a line to execute a line
    • advantages
      • There is no need to recompile for different platforms
    • disadvantages
      • Slow running speed

Scripting language

Dynamic languages -> Scripting languages -> Interpreted languages -> weakly typed languages

Static -> compiled -> weakly typed

  • Scripting language -> scripting engine -> interpreter front and back

    JavaScript: Client-side scripting The JavaScript interpreter is on the browser

    PHP: Server-side scripting The PHP interpreter is on the server

    Python can be compiled into other types of languages through the interpreter

    • Such as Jython, retaining

ECMA

Specification for the European Computer Manufactures Association(European Computer Manufacturing Association) ECMA-262 Scripting language ECMAScript ES5, ES6 Standardized scripting language

Single thread => Simulate multithreading

Single thread -> only one thing can be done at a time

Multithreading -> Can do more than one thing at a time

  • Javascript engines are single-threaded
  1. Rotation time slice
  2. Take turns executing multiple task segments in a short time
  3. Task 1 Task 2
  4. Shard task 1 task 2
  5. Randomly arrange these task fragments into a queue
  6. The task fragments are sent to the JS process in this queue order
  7. The JS thread executes one line after another

coupling

Single accountability for high cohesive, low coupling modules

A block or module is highly functional and highly independent

decoupling

JavaScript key

  1. ECMAScript
    • Syntax, variable keywords, reserved words, values, primitive types, reference types
  2. DOM(Document Object Model) Document object model
    1. W3C specification to add, delete, and change labels
  3. BOM (Browser Object Model) Browser object model
    1. No corresponding specification can be written compatible
      1. Because each browser vendor is different, there is no specification
    2. The event

The value of JS

  1. Raw value -> Basic type
    • Number
    • String
    • Boolean
    • undefined
    • null
  2. Reference value
    1. object
    2. array
    3. function
    4. date
    5. RegExp

Determine type

typeof

console.log(typeof(a)) // if a is undefined, it is undefined
console.log(typeof(typeof(a)) // Typeof returns a string
Copy the code

Declare a variable

Parenthesis operation > Normal operation > Assignment

function

The basic function

// The basic function declaration
function text (parameter){
    // Execute the statement
}
// Anonymous function expressions function literals
var text = function text1 (){
    // Execute the statement
    Text1 is not visible
}
// Parameter -> placeholder -> formal placeholder -> formal parameter -> parameter
function test(a,b){
    // An error is reported if this parameter is not passed
    // The parameter is equivalent to declaring inside a function such as var a
    console.log( a + b )
}
// Actual parameters => In sequence => The change of position is invalid
// If you pass extra arguments in a function call argument that are not equal to the number of parameters, no error is reported
test(11.22)

function test(a,b){
    b = 3
  	console.log( arguments[1])// Undefuned is printed
    // If the parameter is not passed in => b= > undefined => undefined cannot be assigned
    If you pass a value in an argument -> you can change the value inside the function -> If you do not pass a value in the argument -> you cannot change the value inside the function
}
test(1)

function test(a,b){
    a = 3
  	console.log( arguments[0])// Arguments [0
    // Arguments are stored in stack memory
    // Arguments are mapped to the values of arguments (); // Arguments are mapped to the values of arguments () Arguments [0] can also change because of one-to-one correspondence
}
test(1.2)
Copy the code

Every function must have a return. If you don’t write a return, the JS engine adds a return at the end of the function by default

The use of the return

  1. Terminate function execution, where do you want to terminatereturnWhere is the writing
  2. Return any value

Global variables VS local variables

  • Global declarations are called global variables
  • Declarations inside functions are called local variables
    • You can use global variables in a function and cannot call variables in a function globally

Functional programming

  • A fixed function or process by which a program is encapsulated, implementing a fixed function or program in this package

You need an exit and an entrance

  • The entry is the parameter and the exit is the return value

The function initializes arguments

Default value of initialization parameter :undefined

// a = 1 is es6 syntax
function test(a=1,b){
    console.log(a,b)
    // A is 1, b is 22
    // Arguments are mapped to parameters. Arguments take the value of undefined and conversely arguments take the value of undefined
}
test(undefined.22)
Copy the code

precompiled

  1. Check for grammatical errors throughout
  2. Precompilation process
  3. Explain a line, execute a line

Functions declare global promotion, variables only declare promotion, assignment does not promote

Implied global variable

imply global variable

// If a variable is assigned an undeclared value, it will be mounted to the global object Window
b = 22 
console.log(window.b) 
Copy the code

AO activation object

Active object, function execution context

  1. Creates an AO object and looks for the parameters and variable declarations in the function
  2. Find the parameter value of the argument and assign it to the parameter
  3. Look for function declarations inside functions
  4. perform
function fn (a){
    var a = 1
    function a (){}
}
fn(2)
AO = {
    // a:undefined
    // a:2
    a : function a (){}}Copy the code

If there is no such value in AO, GO will look for it

GO global object

Global execution context

  1. Finding variable declarations
  2. Find a function declaration
  3. perform

GO ===window

var fn1 = 123
function fn1(){}

GO: {// fn1 : undefined
    fn1 : function fn1(){}}Copy the code