考察js作用域、变量提升的面试题

输出结果是什么?

<!DOCTYPE html>    
<html lang="en">    
<head>    
    <meta charset="UTF-8">    
    <title>考察js作用域、变量提升的面试题</title>  
</head>    
<body>  
<script type="text/javascript">
var name = 'World!';
(function () {
    if (typeof name === 'undefined') {
        var name = 'Jack'
        console.log('Goodbye ' + name)
    } else {
        console.log('Hello ' + name)
    }
})()
</script>      
</body>    
</html>

结果是:Goodbye Jack

 

 

posted @ 2019-03-19 12:02  徐同保  阅读(196)  评论(0编辑  收藏  举报