不二如是 发表于 2017-4-1 10:14:50

已有 13 人购买  本主题需向作者支付 2 鱼币 才能浏览 购买主题

shishunfu 发表于 2017-5-5 10:46:15

<!DOCTYPE html>
<html lang="en">
<head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>进击的巨人--JS</title>
        <script>
                /*var h="haha";*/
      var name="鱼C根部";
      var address=null;
      //函数的定义
      function first_function(){
            name=name+" 守护鱼C黑夜的组织";
            address="快来加入吧~";
      }
      //函数的调用
      first_function();
      alert("鱼C神秘组织:"+name+"广邀豪杰:"+address);
      alert(h);
        </script>
</head>
<body>
</body>
</html>

MSK 发表于 2017-7-10 15:26:14

交!作!业!
误打误撞发现了换行符{:10_282:}

<!DOCTYPE html>
<html>
<head>
        <title>007</title>
        <meta charset='utf-8' http-equiv='Content-type' content='text/html'>
        <script type="text/javascript">
        var name1 = '鱼C根部';
        name2 = '守护鱼C黑夜的组织'
        function frist_function(){
                addr = '   \n快来加入吧~!';
                words = name1 + '、' + name2 + addr;
        }
        frist_function();
        alert(words);
        alert('name1 ---->' + name1);
        alert('name2 ---->' + name2);
        alert('addr ---->' + addr);
        alert('words ---->' + words);
        </script>
</head>
<body>
</body>
</html>

yanmeilemon 发表于 2018-6-21 13:58:52

{:5_91:}

克里斯保罗 发表于 2019-9-30 16:29:29

<!DOCTYPE html>
<html lang="en">
<head>
        <meta charset="UTF-8">
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
        <title>title</title>
        <script type="text/javascript">
                name = 'Anthony';
                function first_function(argument) {
                        name += "New York";
                        address="The Empire State";
                }
                var hahah = "看看定义在后面能不能用~"
                first_function();
                alert("New York's Boss "+name+"address: "+address);
                alert(hahah);
                //var hahah = "看看定义在后面能不能用~"

        </script>
</head>
<body>
       
</body>
</html>

你在意在便在 发表于 2019-11-8 21:18:48

{:10_256:}分清全局变量和局部变量,并可以使用 typeof 来查看变量是否定义
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
<script type="text/javascript">
    var name="鱼C根部";
    // 定义
    function first_function(){
      name=name+"守护鱼C黑夜的组织";
      address = "快来加入吧~";
    }
   // 调用
    first_function();
    alert("鱼C神秘组织:"+name+" 广邀豪杰:" +address);
    /* alert(hahaha); */ //未定义会报错
    /* 给hahaha进行赋值再执行试试 */
    var hahaha = "这下我有定义了";
    alert(hahaha);
</script>
</body>
</html>

suchamy 发表于 2020-3-22 14:56:12

为什么这里的address变量在函数调用完了之后没有被释放掉呢。。
页: [1]
查看完整版本: 0 0 0 7 ★ 变量“作用域”之#全局变量