# 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;
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://petercheng7788.gitbook.io/developer-note/programming-language/javascript/const-vs-let-vs-var.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
