JS中 关于作用域的几个例子

//作用域
     var x1 = 1;
     function f1(x1,y1 = x1) {
         console.log(y1)
     };
     f1(12);    // 12
     f1();  // undefined

    //  console.log(x1);

     var x2 = 1;
     function f2(y2 = x2) {
         let x2 = 20;
         console.log(y2)
     };
     f2();   // 1

     function f3(y3 = x3) {
        //  var x3= 10;
         let x3 = 20;
         console.log(y3)
     };
     f3();   //x is not defined

你可能感兴趣的:(JavaScript基础,javascript,作用域)