0%

JS中的var let const

  • var属于function scope 而 let和const属于block scope。

  • let和const属于ES6新特性。

  • const定义的变量类似Java中的final关键字,其值不可修改。

1
2
3
4
5
6
7
8
9
10
function(){
var a = 123;
if(a == 123){
let b = 456;
}
console.log(b); // Uncaught ReferenceError: b is not defined
const c = 789;
c = 0; // Uncaught TypeError: Assignment to constant variable.
}
console.log(a); // Uncaught ReferenceError: a is not defined

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

1
$ hexo new "My New Post"

More info: Writing

Run server

1
$ hexo server

More info: Server

Generate static files

1
$ hexo generate

More info: Generating

Deploy to remote sites

1
$ hexo deploy

More info: Deployment