> For the complete documentation index, see [llms.txt](https://petercheng7788.gitbook.io/developer-note/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://petercheng7788.gitbook.io/developer-note/programming-language/javascript/const-vs-let-vs-var.md).

# Const VS Let VS Var

## Background

* var happened first , let and const occurs in es6
* They are not types, but are keywords, since javaScript is weak and dynamic(check errors after running the program) typed

## Const

* the value of variable cannot be changed
* cannot re-declared
* cannot be undefined

## Let

* Cannot re-declared the variable &#x20;
* Example:

```javascript
let test = 2;
let test = 3; // result :failed
```

* block-scoped
* Example:

```javascript
 function(){
   if(true){
     let i = 1;
    }
    console.log(i);// error
  }
```

## Var

* Function-Scoped
* Can be re-declared
* Hoisting
* Example:

```javascript
var test = 2;
var test = 3; // result : test will be 3

console.log(x);
// undefined
var x = 10;
```
