Merge pull request #75 from Kurczok/master

Grammatical changes
This commit is contained in:
Ilya Kantor 2017-07-10 09:38:32 +03:00 committed by GitHub
commit d45de3608a
6 changed files with 39 additions and 39 deletions

View file

@ -4,7 +4,7 @@ The tutorial that you're reading is about core JavaScript, which is platform-ind
But, we need a working environment to run our scripts, and, just because this book is online, the browser is a good choice. We'll keep the amount of browser-specific commands (like `alert`) to a minimum, so that you don't spend time on them if you plan to concentrate on another environment like Node.JS. On the other hand, browser details are explained in detail in the [next part](/ui) of the tutorial.
So first, let's see how to attach a script to the webpage. For server-side environments, you can just execute it with a command like `"node my.js"` for Node.JS.
So first, let's see how to attach a script to a webpage. For server-side environments, you can just execute it with a command like `"node my.js"` for Node.JS.
[cut]
@ -45,7 +45,7 @@ The `<script>` tag contains JavaScript code which is automatically executed when
## The modern markup
The `<script>` tag has a few attributes that are rarely used nowadays, but we can find them in the old code:
The `<script>` tag has a few attributes that are rarely used nowadays, but we can find them in old code:
The `type` attribute: <code>&lt;script <u>type</u>=...&gt;</code>
@ -70,7 +70,7 @@ Comments before and after scripts.
If we have a lot of JavaScript code, we can put it into a separate file.
The script file is attached to HTML with `src` attribute:
The script file is attached to HTML with the `src` attribute:
```html
<script src="/path/to/script.js"></script>
@ -78,7 +78,7 @@ The script file is attached to HTML with `src` attribute:
Here `/path/to/script.js` is an absolute path to the file with the script (from the site root).
It is also possible to provide a path relative to the current page. For instance, `src="script.js"` would mean a file `"script.js"` from the current folder.
It is also possible to provide a path relative to the current page. For instance, `src="script.js"` would mean a file `"script.js"` in the current folder.
We can give a full URL as well, for instance:
@ -99,7 +99,7 @@ As a rule, only the simplest scripts are put into HTML. More complex ones reside
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).
After this, other pages which want the same script will take it from the cache instead of downloading it. So the file is actually downloaded only once.
After this, other pages that want the same script will take it from the cache instead of downloading it. So the file is actually downloaded only once.
That saves traffic and makes pages faster.
```
@ -134,4 +134,4 @@ The example above can be split into two scripts to work:
- A script in an external file can be inserted with `<script src="path/to/script.js"></script>`.
There is much more about browser scripts and their interaction with the web-page. But let's keep in mind that this part of the tutorial is devoted to JavaScript language, so we shouldn't distract ourselves from it. We'll be using a browser as a way to run JavaScript, which is very convenient for online reading, but yet one of many.
There is much more to learn about browser scripts and their interaction with the web-page. But let's keep in mind that this part of the tutorial is devoted to the JavaScript language, so we shouldn't distract ourselves from it. We'll be using a browser as a way to run JavaScript, which is very convenient for online reading, but yet one of many.

View file

@ -85,16 +85,16 @@ Now we have the "All fine now" message and then `1` and `2`.
The error in the no-semicolon variant occurs because JavaScript does not imply a semicolon before square brackets `[...]`.
So, because the semicolon is not auto-inserted, the code in the first example is treated as a single statement, that's how the engine sees it:
So, because the semicolon is not auto-inserted, the code in the first example is treated as a single statement. That's how the engine sees it:
```js run no-beautify
alert("There will be an error")[1, 2].forEach(alert)
```
But it should be two separate statements, not a single one. Such a merging in this case is just wrong, hence the error. There are other situations when such thing happens.
But it should be two separate statements, not a single one. Such a merging in this case is just wrong, hence the error. There are other situations when such a thing happens.
````
It's recommended to put semicolons between statements even if they are separated by newlines. This rule is widely adopted by the community. Let's note once again -- *it is possible* to leave out semicolons most of time. But it's safer, especially for a beginner -- to put them.
It's recommended to put semicolons between statements even if they are separated by newlines. This rule is widely adopted by the community. Let's note once again -- *it is possible* to leave out semicolons most of the time. But it's safer, especially for a beginner -- to use them.
## Comments
@ -126,9 +126,9 @@ alert('Hello');
alert('World');
```
The content of comments is ignored, so if we put a code inside <code>/&#42; ... &#42;/</code> it won't execute.
The content of comments is ignored, so if we put code inside <code>/&#42; ... &#42;/</code> it won't execute.
Sometimes it comes handy to temporarily disable a part of the code:
Sometimes it comes in handy to temporarily disable a part of code:
```js run
/* Commenting out the code
@ -138,13 +138,13 @@ alert('World');
```
```smart header="Use hotkeys!"
In most editors a line of code can be commented out by `key:Ctrl+/` hotkey for a single-line comment and something like `key:Ctrl+Shift+/` -- for multiline comments (select a code and press the hotkey). For Mac try `key:Cmd` instead of `key:Ctrl`.
In most editors a line of code can be commented out by `key:Ctrl+/` hotkey for a single-line comment and something like `key:Ctrl+Shift+/` -- for multiline comments (select a piece of code and press the hotkey). For Mac try `key:Cmd` instead of `key:Ctrl`.
```
````warn header="Nested comments are not supported!"
There may not be `/*...*/` inside another `/*...*/`.
This code will die with an error:
Such code will die with an error:
```js run no-beautify
/*
@ -156,6 +156,6 @@ alert( 'World' );
Please, don't hesitate to comment your code.
Comments increase the overall code footprint, but that's not a problem at all. There are many tools which minify the code before publishing to production server. They remove comments, so comments do not appear in the working scripts. So, the comments do not have any negative effects on production at all.
Comments increase the overall code footprint, but that's not a problem at all. There are many tools which minify the code before publishing to the production server. They remove comments, so they don't appear in the working scripts. Therefore comments do not have any negative effects on production at all.
Further in the tutorial, there will be a chapter <info:coding-style> that also explains how to write better comments.