码迷,mamicode.com
首页 > 其他好文 > 详细

let全解析

时间:2018-05-22 18:19:36      阅读:235      评论:0      收藏:0      [点我收藏+]

标签:script   utf-8   define   出错   自己的   fine   head   cee   uncaught   

再一次的学习let,更加深入

/**
 * let关键字的特点
 * 1。不会预处理, 不存在变量提升
 * 2。有自己的作用域,不可以全局或者作用域内重复声明
 */
 
 let关键字的应用: 循环遍历加监听
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    window.onload = function () {
        // let aa = 1

        console.log(aaaa)
        var aaaa = 1
        // 变量提升(预处理)
        // 打印的是  undefined

        console.log(bbbb)
        let bbbb = 1
        // 变量提升(预处理)  这里出错  使用let , 不存在预处理 !!!!  , 打印的是 Uncaught ReferenceError: bbbb is not defined
        // at window.onload

        let aa = 0
        console.log(aa)

        function aaa() {
            let aa = 1
            console.log(aa)
        }
        aaa()
    }
</script>

</body>
</html>

(完)

let全解析

标签:script   utf-8   define   出错   自己的   fine   head   cee   uncaught   

原文地址:https://www.cnblogs.com/ganping/p/9073099.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!