JavaScript interview question series-the difference between var, let and const

JavaScript Interview Question Series:
1
: Tell me about the difference between var, let and const:
var: no definite scope, it is weakly typed, supports variable promotion,
let: has block-level scope, ES6 syntax, no repeated declarations, Temporary dead zone. Can not access
const: ES6 syntax through window variables , with block-level scope, no repeated declarations, temporary dead zone, after a variable is declared, it cannot be changed, and an error is reported if the change is made, the declaration must be initialized ( Both assigned)

2: What is the difference between arrow functions and ordinary functions? (When it comes to arrow functions, there will be related questions about this)
Ordinary function this:
1. This always represents its direct caller.
2. By default, no direct caller is found, this refers to window.
3. In strict mode, this in a function without a direct caller is undefined.
4. Use call, apply, bind binding, this refers to the bound object.

Arrow function this
1. When using => to define the function, this refers to the object where it is defined, not where it is used Object
2. Cannot be used as a constructor, which means that the new command cannot be used, otherwise an error will be thrown;
3. The arguments object cannot be used;
4. The yield command cannot be used;

/ 普通函数
        function f1(){
    
    
            console.log("我是普通函数"); 
        }
        f1()
/箭头函数: 箭头函数相当于匿名函数,如果没有参数,就只写一个(),有参数直接写在(参数1,参数2let f2 = () =>console.log("ddd");// 如果函数里面只有一个表达式,可以省略{}和return
        f2()
        let f3 = ()=>{
    
                       // 如果有多个表达式则不能省略{}和return
            console.log("我是箭头函数");
            f1()
        }
        f3()

Check related information: https://www.cnblogs.com/1825224252qq/p/11772370.html
https://www.jianshu.com/p/c26c9c1c73f0

Guess you like

Origin blog.csdn.net/jsxiaochen/article/details/108276209