zoukankan      html  css  js  c++  java
  • js的作用域题

    ---恢复内容开始---

    1.

    var a = 12
      function fn() {  
      console.log(a) 
       var a = 45;  
      console.log(a)  
    }
    fn()
    2.
    function fn() {  
      console.log(11)  
        function ff() {    
        console.log(22)  
      }  
      ff()
    }
    fn()
    3.
    function fn() { 
      console.log(5)  

      fn()  
    }
    fn()
    4.
    var a = 123;

      function fun() {
        alert(a);
      }
      fun();
    5.
    var a = 123;

      function fun() {
      alert(a);
      var a = 456;
      }
      fun();
    alert(a);
    6.
    var a = 123;

      function fun(a) {
        alert(a);
        a = 456;
      }
      fun();
    alert(a);
    7.
    var a = 123;

      function fun(a) {
          alert(a);
          a = 456;
    }
    fun(123);
    alert(a);
    8.
    function test(a, b) {
      console.log(a);
      console.log(b);
      var b = 234;
      console.log(b);
      a = 123;
      console.log(a);

      function a() {}
      var a;
      b = 234;
      var b = function() {}
      console.log(a);
      console.log(b); 
    }
    test(1);
    9.
    function fn(a) {
      console.log(a);
      var a = 123;
      console.log(a);

    function a() {}
    console.log(a);
    var b = function() {}
    console.log(b);

    function d() {}
    }
    fn(1);
    10.
    function fn() {  

      console.log(12)
    }
    var as = fn()

    console.log(as)

    11.
    function fn() {  
    console.log(12)  

    return 45;  
    console.log(456)  
    }

    fn()
    12.
    var a = 12; 
    function fn() {  
    console.log(a)  

    return 4;  
    var a = 45;
    }

    fn()
    13.
    var a = 100; 
    function testResult() {  
      var b = 2 * a  
      var a = 200  
      var c = a / 2  

      alert(b)  

      alert(c)
    }
    testResult()

     以上为作用域问题,如有不会请加qq:2521387292

    ---恢复内容结束---

  • 相关阅读:
    关于AJAX与form表单提交数据的格式
    MongoDB
    Redis
    在django中使用django_debug_toolbar进行日志记录
    python第三方库,你要的这里都有
    Django之用户认证auth模块
    Django中常用命令
    form表单钩子,局部钩子和全局钩子
    当我开始爱自己
    FOR YOU
  • 原文地址:https://www.cnblogs.com/guhuai/p/10066263.html
Copyright © 2011-2022 走看看