# Variables in js
## Variable declaration
In [[JavaScript]], variables are undefined when initialized until a value is explicitly assigned to them. There is no need to define a variable as being of a type until this value assignation happens.
There are three ways to declare a variable.
### var
`var` is function-scoped. If declared within a loop, it will also be available to the function within which the loop is created.
It is `undefined` if you access it before it's been declared.
### let
`let` is block-scoped. If declared within a loop, it won't be available outside the loop.
It throws a `ReferenceError` if you access it before it's been declared
### const
`const` is block-scoped.
It cannot be reassigned to a new value, although if it's an object, you can still change its properties.
### Which to use?
- `const` when a variable's value should not change
- `let` in all other circumstances.
## References