javascript的暂时性死区

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


</head>
<body>
<script>
    
    var PI=3.1415926
   if(true){
       console.log(PI) //无影响
       var PI;
   }



    let PI1=3.1415926
   if(true){
       console.log(PI1) //报错,会形成暂时性死区
       let PI1;
   }

</script>
</body>
</html>

posted @ 2024-07-28 17:13  Bre-eZe  阅读(2)  评论(0编辑  收藏  举报