This is the sixth day of my participation in the August More text Challenge. For details, see: August More Text Challenge

Continuous update, can be used as a beginner’s learning route, can refer to the following, learning progress is not particularly catch up!

With their own understanding, simple and comprehensive summary of basic knowledge, most of the content is the vernacular content, the foundation of the foundation to deepen understanding!

Consolidate the basic knowledge of learning JavaScript, deepen the understanding of memory, to build a firm foundation! Come on

For more detailed learning – it is recommended to view the MDN-javascript documentation, (Little Red Book/White Paper/Blue Book /..) Learn to advance!

Read more: Previous update review

【 Day1 】 【 Day1 】

[day2], [day3], [day4], [day5]

Let’s get started! Follow up – Continue to comb through and update today’s knowledge

1, the previous review – comb knowledge points

  • Function:
  • Function parameters:
    • Parameter and argument
    • A copy of the argument to the receiver function:arguments
function fn() {
  // ...
}
fn(2.3.4.5.6)
Copy the code
  • Function returns:
    • throughreturnThere is and only one return
    • A function encountersreturnThe following statement is not executed
    • Used inside the function bodyreturn

2. Scope of variables

2.1 Scope: Scope

Global variables:

Scope: Variables are valid throughout the program from start to end

A variable defined outside a function (global with or without var) is an explicit global variable

A variable defined by var is not an implicit global variable within the body of a function

2.2 Scope chain ** :

The variable first looks up inside the function body,

  • If found inside the body of the function, returns (indicating that the variable is a local variable),
  • Otherwise I’m going to go outside of the function body and if I find it, I’m going to operate on a global variable and if I don’t find it inside or outside of the function,

Determine if the variable definition has var

  • There arevarIt’s a local variable,
  • There is novarIt’s a global variable

This process of searching is called scoping

2.3 Local variables:

Scope of action:

  • Local variables are valid only within the body of the function
  • Jump out of function body local variable autodestruct

A variable explicitly defined within the body of a function via var

All formal parameters are local variables

2.4 Variable improvement:

A variable declared with var inside the body of the function is promoted to the top of the body,

Only promote declarations but do not assign values

function fn() {
  alert(num)
  var num = 20
}
Copy the code

Is equivalent to:

function fn() {
  var num
  alert(num) // undefined
  num = 20
}
Copy the code
  • In the actual project:
    • Local variables are usually used
    • To prevent global variable contamination
    • Try to avoid global variables

3. Recursive function calls

  • Functions call themselves (disadvantages are performance consuming)
  • The nature of recursion: it implements loops
  • When recursion is executed, because the function is called repeatedly, the storage space will be constantly opened up and the execution efficiency will be low
function fn(n){  // The n loop variable n will have an initial argument value
  if( n == 1) {// Final value cycle conditions
    return 1;
  }else{
    return n*fn(n-1);  n*fn(n-1)  // Loop body step size: n-1}}function fn(n){
  var fac = 1;
  for(var i = 1 ; i <= n ; i++){
    fac \*= i;
  }
  return fac;
}
Copy the code

4. Relationships between functions and events

  • Event: Some operation on an element
  • Three elements of the event:
    • Event source: Usually a noun is static
    • Event: Usually a verb
    • Event handler: Typically the result of a function’s handling of the event source

Function and event relationships: All events are generally dependent on function execution

5. Event type

5.1 Mouse Events

  • The onclick click
  • Ondblclick double-click
  • Oncontextmenu right-click
  • Onmouseover move
  • Onmouseout removed
  • Onmouseenter move
  • Onmouseleave removed
  • Onmousemove mobile
  • Onmousewheel roller
  • Onmousedown press
  • Onmouseup lift

5.2 Keyboard Events

  • Onkeyup lift
  • Onkeydown press
  • Onkeypress press + lift

5.3 Form Events

  • Onfocus Gets the focus
  • Lose focus
  • Onsubmit Form submission
  • Onchange change

5.4 Page Events

  • Onload Page load event
  window.onload= function(){when does the code execute here: it needs to be executed after all elements of the page have been loaded}Copy the code

6. How events operate on page elements (js operations on elements)

  • Operating style

Note: Compound properties are written in small humps such as fontSize

  • Action attribute

SRC is called the attribute of the img element

Obj. Attribute name = Value

  • Operating content

    • If the form obj.value = “value”;
    • Non-form operations: obj.innerHTML = “value”;

Come on, dreamers

Learning is a continuous process, stick to it, there will be harvest!

Accumulate over a long period of time, consolidate the foundation, early into dafang!

It is not easy to insist, adhere to a long time is not easy

Calm Down & Carry On!