minor fixes
This commit is contained in:
parent
8f2ae7eb20
commit
9cb597e229
1 changed files with 14 additions and 14 deletions
|
@ -80,20 +80,6 @@ let user = 'John'
|
|||
|
||||
Technically, all these variants do the same thing. So, it's a matter of personal taste and aesthetics.
|
||||
|
||||
````warn header="Declaring twice triggers an error"
|
||||
A variable should be declared only once.
|
||||
|
||||
A repeated declaration of the same variable is an error:
|
||||
|
||||
```js run
|
||||
let message = "This";
|
||||
|
||||
// repeated 'let' leads to an error
|
||||
let message = "That"; // SyntaxError: 'message' has already been declared
|
||||
```
|
||||
So, we declare a variable once, and then should refer to it without `let`.
|
||||
````
|
||||
|
||||
````smart header="`var` instead of `let`"
|
||||
In older scripts, you may also find another keyword: `var` instead of `let`:
|
||||
|
||||
|
@ -148,6 +134,20 @@ alert(hello); // Hello world!
|
|||
alert(message); // Hello world!
|
||||
```
|
||||
|
||||
````warn header="Declaring twice triggers an error"
|
||||
A variable should be declared only once.
|
||||
|
||||
A repeated declaration of the same variable is an error:
|
||||
|
||||
```js run
|
||||
let message = "This";
|
||||
|
||||
// repeated 'let' leads to an error
|
||||
let message = "That"; // SyntaxError: 'message' has already been declared
|
||||
```
|
||||
So, we declare a variable once, and then should refer to it without `let`.
|
||||
````
|
||||
|
||||
```smart header="Functional languages"
|
||||
It's interesting to note that there exist [functional](https://en.wikipedia.org/wiki/Functional_programming) programming languages, like [Scala](http://www.scala-lang.org/) or [Erlang](http://www.erlang.org/) that forbid changing variable values.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue