let 是取代var

在块级作用域里面有效

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <script type="application/javascript">
        {
            var a=1;
            let b=2;

        }
        console.log(a);
    console.log(b);
    </script>
</body>
</html>

 

let  const关键字

 

cons定义常量

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <script type="application/javascript">
           const a=12;
           a=6;
           console.log(a);
    </script>
</body>
</html>

  

 

相关文章:

  • 2021-07-06
  • 2021-05-27
  • 2021-11-06
  • 2021-12-11
  • 2021-06-04
  • 2021-10-12
  • 2021-06-24
猜你喜欢
  • 2021-11-14
  • 2021-06-05
  • 2022-12-23
相关资源
相似解决方案