Merge branch 'master' of https://github.com/iliakan/javascript-tutorial-en
This commit is contained in:
commit
733b0c66b5
19 changed files with 34 additions and 29 deletions
|
@ -37,7 +37,7 @@ For instance:
|
|||
```
|
||||
|
||||
```online
|
||||
You can run the example clicking on a "Play" button in it's right-top corner.
|
||||
You can run the example by clicking on the "Play" button in its right-top corner.
|
||||
```
|
||||
|
||||
The `<script>` tag contains JavaScript code which is automatically executed when the browser meets the tag.
|
||||
|
@ -49,7 +49,7 @@ The `<script>` tag has a few attributes that are rarely used nowadays, but we ca
|
|||
|
||||
The `type` attribute: <code><script <u>type</u>=...></code>
|
||||
|
||||
: The old standard HTML4 required a script to have the type. Usually it was `type="text/javascript"`. The modern HTML standard assumes this `type` by default, no attribute is required.
|
||||
: The old standard HTML4 required a script to have a type. Usually it was `type="text/javascript"`. The modern HTML standard assumes this `type` by default, no attribute is required.
|
||||
|
||||
The `language` attribute: <code><script <u>language</u>=...></code>
|
||||
: This attribute was meant to show the language of the script. As of now, this attribute makes no sense, the language is JavaScript by default. No need to use it.
|
||||
|
@ -95,7 +95,7 @@ To attach several scripts, use multiple tags:
|
|||
```
|
||||
|
||||
```smart
|
||||
As a rule, only simplest scripts are put into HTML. More complex ones reside in separate files.
|
||||
As a rule, only the simplest scripts are put into HTML. More complex ones reside in separate files.
|
||||
|
||||
The benefit of a separate file is that the browser will download it and then store in its [cache](https://en.wikipedia.org/wiki/Web_cache).
|
||||
|
||||
|
|
|
@ -114,7 +114,7 @@ alert('Hello');
|
|||
alert('World'); // This comment follows the statement
|
||||
```
|
||||
|
||||
**Multiline comments start with a forward slash and an asterisk <code>"/*"</code> and end with an asterisk and a forward slash <code>"*/"</code>.**
|
||||
**Multiline comments start with a forward slash and an asterisk <code>/*</code> and end with an asterisk and a forward slash <code>*/</code>.**
|
||||
|
||||
Like this:
|
||||
|
||||
|
|
|
@ -231,7 +231,7 @@ The last three lines may need additional explanations:
|
|||
There are 7 basic types in JavaScript.
|
||||
|
||||
- `number` for numbers of any kind: integer or floating-point.
|
||||
- `string` for strings. A string may have one more more characters, there's no separate single-character type.
|
||||
- `string` for strings. A string may have one or more characters, there's no separate single-character type.
|
||||
- `boolean` for `true`/`false`.
|
||||
- `null` for unknown values -- a standalone type that has a single value `null`.
|
||||
- `undefined` for unassigned values -- a standalone type that has a single value `undefined`.
|
||||
|
|
|
@ -93,7 +93,7 @@ alert( 1 + '2' ); // '12' (string to the right)
|
|||
alert( '1' + 2 ); // '12' (string to the left)
|
||||
```
|
||||
|
||||
That only happens when one of arguments is a string. Otherwise values are converted to numbers.
|
||||
That only happens when one of the arguments is a string. Otherwise, values are converted to numbers.
|
||||
````
|
||||
|
||||
## ToBoolean
|
||||
|
|
|
@ -176,7 +176,7 @@ alert( null >= 0 ); // (3) *!*true*/!*
|
|||
|
||||
Yeah, mathematically that's strange. The last result states that "`null` is equal or greater than zero". Then one of the comparisons above must be correct, but they are both falsy.
|
||||
|
||||
The reason is that an equality check `==` and comparisons `> < >= <=` work differently. Comparisons convert `null` to a number, hence treat it as `0`. That's why (1) `null >= 0` is true and (3) `null > 0` is false.
|
||||
The reason is that an equality check `==` and comparisons `> < >= <=` work differently. Comparisons convert `null` to a number, hence treat it as `0`. That's why (3) `null >= 0` is true and (1) `null > 0` is false.
|
||||
|
||||
From the other hand, the equality check `==` for `undefined` and `null` works by the rule, without any conversions. They equal each other and don't equal anything else. That's why (2) `null == 0` is false.
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ For example:
|
|||
```js run
|
||||
let isBoss = confirm("Are you the boss?");
|
||||
|
||||
alert( isBoss ); // true is OK is pressed
|
||||
alert( isBoss ); // true if OK is pressed
|
||||
```
|
||||
|
||||
## Summary
|
||||
|
|
|
@ -385,7 +385,7 @@ These are exceptions. Generally functions names should be concise, but descripti
|
|||
|
||||
## Functions == Comments
|
||||
|
||||
Functions should be short and do exactly one thing. If that thing is big, maybe it's worth to split the function into few smaller functions. Sometimes following this rule may be not easy, but it's a definitely good thing.
|
||||
Functions should be short and do exactly one thing. If that thing is big, maybe it's worth to split the function into few smaller functions. Sometimes following this rule may not be that easy, but it's a definitely good thing.
|
||||
|
||||
A separate function is not only easier to test and debug -- its very existence is a great comment!
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue