1. 程式人生 > >js之作用域

js之作用域

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>

<script>


name='randomlee';


function func() {
    var name='lee';
    function inner() {
        console.log(name);

    }
     var name='random';
    return inner;
}


var ret =func();

ret();
console.log(name)

</script>
</html>

  js的作用域作用在函式體內且在函式執行之前作用域就已經生成