js advanced day 4

A strict mode (use strict)

(1) Add use strict at the beginning of the entire file

(2) The very beginning of the function

(3) In es6, it is in strict mode by default

Why set strict mode?

(1) Eliminate some unreasonable and imprecise places in js syntax, and reduce some weird behaviors

(2) Eliminate some unsafe parts of the js code to ensure the safe operation of the js code

(3) Strict mode can run faster than non-strict mode .

There are many strict mode syntax notes:

(1) Missing declarations are not allowed, without var

(2) Octal not allowed: a syntax error will be reported

(3) It is not allowed to write the function in if

(4) Formal parameter names are not allowed to be repeated (declare formal parameters with the same name)

(5) It is not allowed to declare the same attribute for the object

(6) There is no one-to-one correspondence between arguments and formal parameters

(6) this in function no longer points to window

2. Review some old knowledge

undefined appears:

Access a property that does not exist in an object

Accessing elements that are not in the array

function returns no value

declared no assignment

Notes on let:

Can't raise using let

Cannot be reassigned, an error will be reported

Cannot be a property of a Windows object

let{} will form a block-level scope

The difference between adding var and not adding var:

1. Adding var in the global scope can improve, but not adding var can not improve

2. In the global scope, adding var or not adding var can be used as an attribute of the window object

3. In the local scope, no var can be used as the property of the window object

4. Those without var can only be used as global variables, not local variables

5. Variables with var cannot be deleted, and variables without var can be deleted

3. Recursive function

The programming trick where a program calls itself is called recursion.

Simplify large-scale problems layer by layer to obtain small-scale problems, then solve small problems, and then solve large problems layer by layer

Recursive function: Inside a function, he calls himself again and needs an exit

function f(){

          f();//Remember to export

}

Remember to solve these few small examples

Use recursive thinking to find the accumulation of 100
Use recursive thinking to find the 20th item in the Fibonacci sequence
Use recursion to find the sum of the elements in the array
Use recursive thinking to find the value of the Nth item of 1,3,5,7,9,.... Indexes start at 0.
Using recursive thinking, find the sum of the first N items of 1, 3, 5, 7, 9,...
Use recursive thinking to find the value of the Nth item of 0,2,4,6,8,...
Using recursive thinking, find the sum of the first N items of 0, 2, 4, 6, 8, ...

 

Guess you like

Origin blog.csdn.net/zwy1231/article/details/103416471