js中存在块的概念,但是块不作为作用域使用;js的作用域的概念只存在于function中:
{}块的作用只是用来将部分代码归类,便于代码区分,提高代码的可阅读性和后期维护
<script>
//函数声明
function fn1(){
var a=10;
console.log(a);
}
{
var c=11;
}
//console.log(a);//报错:a is not defined
console.log(c);//11
</script>