每天CookBook之JavaScript-031

  • 函数的定义
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>031</title>
</head>
<body>
    
</body>
<script type="text/javascript">
(function () {
    console.log(a);
    var a;
})(); 

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

(function () {
    console.log(test());
    function test () {
         return 'hello';  
    }
})(); 

(function () {
    try {
        console.log(test());
    } catch(e) {
        console.log(e);
    }
    var test = function(){
        return 'hello';
    }
})(); 
</script>
</html>  
posted @ 2016-07-13 21:00  4Thing  阅读(100)  评论(0编辑  收藏  举报