Commit 74b7eebf authored by colmoneill's avatar colmoneill
Browse files

working on the var let const documents

parent fa9b6c5b
......@@ -12,6 +12,8 @@ Javascript variables can be declared in three different ways:
* let
* const
## `var`
The latter two have only been available in the latest versions of Javascript and they got created because ultimately, var is considered to be too flexible. Example below:
```
......@@ -26,9 +28,14 @@ console.log(greeter) // "say Hello instead"
```
> So, since times > 3 returns true, greeter is redefined to "say Hello instead". While this is not a problem if you knowingly want greeter to be redefined, it becomes a problem when you do not realize that a variable greeter has already been defined before.
> If you have used greeter in other parts of your code, you might be surprised at the output you might get. This will likely cause a lot of bugs in your code. This is why let and const are necessary.
**var is considered to be risky because it leaves itself open to be updated without you knowing about it**
`var` can still be used in JS because there are still many cases where it is appropriate, plus, if it was suddenly disabled or removed, loads of JS older than 2015 would just stop working. Retro-compatibility is important in programming languages.
## `let` to the rescue
let is superior to var because it is what we call block scoped
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment