Merge pull request #582 from evazorro/patch-1
Update wording and grammar
This commit is contained in:
commit
1889fd8d4e
3 changed files with 10 additions and 10 deletions
|
@ -47,10 +47,10 @@ 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 a type. Usually it was `type="text/javascript"`. It's not required any more. Also, the modern standard totally changed the meaning of this attribute. Now it can be used for Javascript modules. But that's an advanced topic, but we'll talk about modules later in another part of the tutorial.
|
||||
: The old standard HTML4 required a script to have a type. Usually it was `type="text/javascript"`. It's not required any more. Also, the modern standard totally changed the meaning of this attribute. Now it can be used for Javascript modules. But that's an advanced topic; we'll talk about modules later in another part of the tutorial.
|
||||
|
||||
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.
|
||||
: This attribute was meant to show the language of the script. This attribute no longer makes sense, because JavaScript is the default language. No need to use it.
|
||||
|
||||
Comments before and after scripts.
|
||||
: In really ancient books and guides, one may find comments inside `<script>`, like this:
|
||||
|
@ -61,7 +61,7 @@ Comments before and after scripts.
|
|||
//--></script>
|
||||
```
|
||||
|
||||
This trick isn't used in modern JavaScript. These comments were used to hide the JavaScript code from old browsers that didn't know about a `<script>` tag. Since browsers born in the last 15 years don't have this issue, this kind of comment can help you identify really old code.
|
||||
This trick isn't used in modern JavaScript. These comments were used to hide the JavaScript code from old browsers that didn't know about a `<script>` tag. Since browsers released in the last 15 years don't have this issue, this kind of comment can help you identify really old code.
|
||||
|
||||
|
||||
## External scripts
|
||||
|
@ -78,7 +78,7 @@ Here `/path/to/script.js` is an absolute path to the file with the script (from
|
|||
|
||||
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:
|
||||
We can give a full URL as well. For instance:
|
||||
|
||||
```html
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.2.0/lodash.js"></script>
|
||||
|
|
|
@ -263,7 +263,7 @@ function checkAge(age) {
|
|||
*/!*
|
||||
} else {
|
||||
*!*
|
||||
return confirm('Got a permission from the parents?');
|
||||
return confirm('Do you have permission from your parents?');
|
||||
*/!*
|
||||
}
|
||||
}
|
||||
|
@ -334,7 +334,7 @@ So, it effectively becomes an empty return. We should put the value on the same
|
|||
|
||||
## Naming a function [#function-naming]
|
||||
|
||||
Functions are actions. So their name is usually a verb. It should briefly, but as accurately as possible describe what the function does. So that a person who reads the code gets the right clue.
|
||||
Functions are actions. So their name is usually a verb. It should briefly, but as accurately as possible, describe what the function does, so that someone reading the code gets an indication of what the function does.
|
||||
|
||||
It is a widespread practice to start a function with a verbal prefix which vaguely describes the action. There must be an agreement within the team on the meaning of the prefixes.
|
||||
|
||||
|
|
|
@ -78,8 +78,8 @@ let func = sayHi;
|
|||
Everything would work the same. Even more obvious what's going on, right?
|
||||
|
||||
|
||||
````smart header="Why there's a semicolon at the end?"
|
||||
There might be a question, why does Function Expression have a semicolon `;` at the end, and Function Declaration does not:
|
||||
````smart header="Why is there a semicolon at the end?"
|
||||
You might wonder, why does Function Expression have a semicolon `;` at the end, but Function Declaration does not:
|
||||
|
||||
```js
|
||||
function sayHi() {
|
||||
|
@ -198,7 +198,7 @@ The more subtle difference is *when* a function is created by the JavaScript eng
|
|||
|
||||
**A Function Expression is created when the execution reaches it and is usable from then on.**
|
||||
|
||||
Once the execution flow passes to the right side of the assignment `let sum = function…` -- here we go, the function is created and can be used (assigned, called etc) from now on.
|
||||
Once the execution flow passes to the right side of the assignment `let sum = function…` -- here we go, the function is created and can be used (assigned, called, etc. ) from now on.
|
||||
|
||||
Function Declarations are different.
|
||||
|
||||
|
@ -350,7 +350,7 @@ welcome(); // ok now
|
|||
```
|
||||
|
||||
|
||||
```smart header="When to choose Function Declaration versus Function Expression?"
|
||||
```smart header="When should you choose Function Declaration versus Function Expression?"
|
||||
As a rule of thumb, when we need to declare a function, the first to consider is Function Declaration syntax, the one we used before. It gives more freedom in how to organize our code, because we can call such functions before they are declared.
|
||||
|
||||
It's also a little bit easier to look up `function f(…) {…}` in the code than `let f = function(…) {…}`. Function Declarations are more "eye-catching".
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue