在js中,作用域一共分为三类:全局作用域、局部(函数)作用域、块级作用域。
靠里作用域可以访问到定义在靠外的作用域的变量,反之不行。
块级作用域是ES6新推出的概念,用let和const关键字声明变量。所有{}都会形成独立的块级作用域,例如if、for,注意对象的{}不包括在内。