<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>index15-5</title>
    <script type="text/javascript">
        var Msg = "Hello, This in outside of Func1()."
        alert(Msg);  //呼叫函式外的變數Msg
        Func1();      //因呼叫Func1函式,函式內又重心宣告一個Msg變數,所以呼叫函式內的Msg變數
        alert(Msg); //呼叫函式外的變數Msg

        function Func1(){
            var Msg = "Hello,This is inside of Func1()."
            alert(Msg);
        }
    </script>
</html>

 

即便使用相同的名稱做區域變數,JS一樣能夠正確的區分

 

 

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 A&B 的頭像
    A&B

    網頁前端新手上路辛酸史

    A&B 發表在 痞客邦 留言(0) 人氣()