Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
208 commits
Select commit Hold shift + click to select a range
52ed864
Wrong variables name
varkadov Sep 16, 2017
d937a22
Update article.md
azeemansar Sep 16, 2017
c17003f
Fix: Wrong name for Firefox JavaScript engine
justfortherec Sep 16, 2017
cc4d108
Fix computed property example
Sep 16, 2017
42d9eb1
Update article.md
TMatrix Sep 17, 2017
25a65a6
Merge pull request #187 from TMatrix/patch-1
iliakan Sep 17, 2017
1ffd30f
Merge pull request #183 from varkadov/patch-1
iliakan Sep 17, 2017
b31eae8
Merge pull request #186 from samal84/patch-1
iliakan Sep 17, 2017
d314c14
Merge pull request #185 from justfortherec/patch-1
iliakan Sep 17, 2017
8b4cd38
Merge pull request #184 from azeemansar/patch-1
iliakan Sep 17, 2017
9bf0153
minor
iliakan Sep 17, 2017
19f7aa4
Typo - miss letter 't'
TMatrix Sep 17, 2017
3bc6f04
Update LICENSE.md
iliakan Sep 17, 2017
2b166e9
Reggie --> Reggae
micahstubbs Sep 18, 2017
ac8ea0d
typo fix
styopaiv Sep 18, 2017
6be7850
Merge pull request #190 from xibalbaroad/patch-1
iliakan Sep 18, 2017
a2dbffc
Merge pull request #188 from TMatrix/patch-2
iliakan Sep 18, 2017
7cb89de
Merge pull request #189 from micahstubbs/patch-1
iliakan Sep 18, 2017
edbe004
readability
iliakan Sep 18, 2017
a8455f9
Merge branch 'master' of https://github.com/iliakan/javascript-tutori…
iliakan Sep 18, 2017
2e72eed
fix typo, add relevant emoji
zvory Sep 18, 2017
9d28a4c
Typo - miss ')'
TMatrix Sep 18, 2017
67b3d45
Typo - extra letter 'l' before calling function
TMatrix Sep 18, 2017
3f98c72
Typo - expected ')'
TMatrix Sep 18, 2017
c4b905b
Fix typo in readme
alexsr Sep 19, 2017
17154c4
probable typo fixed
zvory Sep 19, 2017
30192ed
Merge pull request #197 from zvory/patch-2
iliakan Sep 19, 2017
bda224f
Merge pull request #196 from alexsr/master
iliakan Sep 19, 2017
d9372f9
Merge pull request #195 from TMatrix/patch-5
iliakan Sep 19, 2017
a9690a6
Merge pull request #194 from TMatrix/patch-4
iliakan Sep 19, 2017
656810c
Merge pull request #193 from TMatrix/patch-3
iliakan Sep 19, 2017
a803757
Merge pull request #192 from zvory/patch-1
iliakan Sep 19, 2017
044ff6f
fix
iliakan Sep 19, 2017
d7eea92
Update article.md
majiix Sep 20, 2017
ab13ef8
Merge pull request #198 from majiix/patch-1
iliakan Sep 20, 2017
67790aa
change incorrect variable name
zvory Sep 20, 2017
3cc5f4c
Merge pull request #199 from zvory/patch-3
iliakan Sep 21, 2017
4b8f153
Typo Fix on '1. Watch' section.
Thespawnexe Sep 21, 2017
f192741
Merge pull request #200 from Thespawnexe/patch-1
iliakan Sep 23, 2017
e0e4f67
Update article.md
ozimos Sep 23, 2017
6085d98
Fix spaces around operator
usernamehw Sep 23, 2017
41dd4a7
Update article.md
Sep 24, 2017
0a2b936
fixes
iliakan Sep 24, 2017
862075a
Merge branch 'master' of https://github.com/iliakan/javascript-tutori…
iliakan Sep 24, 2017
807f0d8
minor
iliakan Sep 24, 2017
d39750f
minor
iliakan Sep 24, 2017
05d39b3
Operator spacing and unclosed quotes
usernamehw Sep 24, 2017
27974ec
Extra space & missing newline
usernamehw Sep 25, 2017
08cca43
Spacing
usernamehw Sep 25, 2017
4c8aedc
Spacing
usernamehw Sep 25, 2017
6b61bef
Spacing
usernamehw Sep 25, 2017
aae4dfd
Typo
usernamehw Sep 25, 2017
b91505a
1 > 02 > 12 > skipping parts (infinite loop)
mikkelsandberg Sep 25, 2017
534c557
Update Solution.md - Task Typo Fix.
Thespawnexe Sep 26, 2017
cbf8281
Merge pull request #212 from Thespawnexe/patch-2
iliakan Sep 26, 2017
84e95d2
Merge pull request #211 from MikkelSandbag/patch-1
iliakan Sep 26, 2017
a1b2d95
Merge pull request #210 from usernamehw/patch-7
iliakan Sep 26, 2017
d9cc401
Merge pull request #209 from usernamehw/patch-6
iliakan Sep 26, 2017
2e63c4f
Merge pull request #201 from ozimos/patch-1
iliakan Sep 26, 2017
d684a53
Merge pull request #202 from usernamehw/patch-1
iliakan Sep 26, 2017
3415953
Merge pull request #203 from shubham0892/patch-1
iliakan Sep 26, 2017
3f12793
Merge pull request #204 from usernamehw/patch-2
iliakan Sep 26, 2017
5a304d4
Merge pull request #205 from usernamehw/patch-3
iliakan Sep 26, 2017
7043ab3
Merge pull request #207 from usernamehw/patch-4
iliakan Sep 26, 2017
6200749
Merge pull request #208 from usernamehw/patch-5
iliakan Sep 26, 2017
9a42935
update article.md for 07-operators.
Thespawnexe Sep 27, 2017
66145f5
Merge pull request #215 from Thespawnexe/patch-3
iliakan Sep 27, 2017
7890fb8
Moar spaces in 07-operators.
Thespawnexe Sep 27, 2017
4245cb4
Fix single quotes mismatch.
Hobinx Sep 27, 2017
163e61a
Fix typo
Hobinx Sep 27, 2017
6dd1311
Merge pull request #218 from Hobinx/patch-1
iliakan Sep 27, 2017
5249604
Merge pull request #219 from Hobinx/patch-2
iliakan Sep 27, 2017
43c1978
Merge pull request #217 from Thespawnexe/patch-4
iliakan Sep 27, 2017
899e3e1
fixes
iliakan Sep 27, 2017
5b16f00
Merge branch 'master' of https://github.com/iliakan/javascript-tutori…
iliakan Sep 27, 2017
4858aaa
Typo
usernamehw Sep 27, 2017
14a926c
Typos & spacing
usernamehw Sep 28, 2017
0aaa498
Spacing
usernamehw Sep 28, 2017
cb37ad9
Spacing
usernamehw Sep 28, 2017
560eb0e
Typo
usernamehw Sep 28, 2017
8407e77
Update article.md
gnardin Sep 28, 2017
2d8ae03
Update article.md
amboz Sep 28, 2017
60609fb
Update article.md
ozimos Sep 28, 2017
fd1eaf4
Typo & spacing
usernamehw Sep 29, 2017
c9d53f1
Merge pull request #220 from usernamehw/patch-1
iliakan Oct 1, 2017
f401a67
Merge pull request #228 from usernamehw/patch-8
iliakan Oct 1, 2017
a0d60d7
Merge pull request #227 from ozimos/patch-2
iliakan Oct 1, 2017
a633642
Merge pull request #226 from amboz/patch-1
iliakan Oct 1, 2017
e6c9e21
Merge pull request #225 from gnardin/patch-1
iliakan Oct 1, 2017
6098562
Merge pull request #224 from usernamehw/patch-6
iliakan Oct 1, 2017
acfb23f
Merge pull request #223 from usernamehw/patch-5
iliakan Oct 1, 2017
5ad8c9f
Merge pull request #222 from usernamehw/patch-3
iliakan Oct 1, 2017
1ece4a5
Merge pull request #221 from usernamehw/patch-2
iliakan Oct 1, 2017
8c6f614
Fixed spy-decorator assignment test
viatsko Oct 1, 2017
501d561
Merge pull request #230 from viatsko/patch-1
iliakan Oct 2, 2017
ed0e64b
minor
iliakan Oct 2, 2017
121c264
fixed
iliakan Oct 2, 2017
2be0ffd
Fix typos, 07-map-set-weakmap-weakset
GeorgySerga Oct 2, 2017
4f584b0
Fix typo, 08-keys-values-entries
GeorgySerga Oct 2, 2017
eb95a01
Merge pull request #231 from GeorgySerga/patch-4
iliakan Oct 2, 2017
cceb7cb
Merge pull request #232 from GeorgySerga/patch-5
iliakan Oct 2, 2017
f51afac
fixed typo on line 44
Oct 5, 2017
6eccd9d
Update article.md
AndreyKalashnik Oct 5, 2017
70d1d87
Fix for replacing the middle item in an Array
amid11 Oct 6, 2017
34c0a5a
Fix typo: 'pop to end' in Arrays:Stacks
johannkm Oct 6, 2017
62c4fb9
Merge pull request #233 from hazkaz/patch-1
iliakan Oct 7, 2017
4ab4223
Merge pull request #236 from johannkm/patch-1
iliakan Oct 7, 2017
61f92a1
Merge pull request #235 from amid11/patch-1
iliakan Oct 7, 2017
ec665a7
Merge pull request #234 from AndreyKalashnik/patch-2
iliakan Oct 7, 2017
3c08cc4
minor
iliakan Oct 7, 2017
de725bd
up
iliakan Oct 11, 2017
71fec32
Spelling mistake in word "behavior"
Zaramont Oct 11, 2017
bfb9ca5
Update article.md
dallin-r-parker Oct 11, 2017
05897fb
Merge pull request #238 from Zaramont/master
iliakan Oct 13, 2017
b4ee23c
Merge pull request #239 from dallin-r-parker/master
iliakan Oct 13, 2017
50e6a15
Typos
usernamehw Oct 13, 2017
089af82
Update article.md
usernamehw Oct 14, 2017
3322f52
correct type mistake
lilifan Oct 14, 2017
e171db0
correct type mistake
lilifan Oct 14, 2017
217eb0e
minor
iliakan Oct 14, 2017
ad296de
Merge branch 'master' of https://github.com/iliakan/javascript-tutori…
iliakan Oct 14, 2017
4d60cd5
fix
iliakan Oct 14, 2017
07d1188
minor
iliakan Oct 14, 2017
53705b8
minor
iliakan Oct 14, 2017
82794dc
Merge pull request #243 from usernamehw/patch-1
iliakan Oct 15, 2017
f1d1cd4
Merge pull request #246 from lilifan/patch-2
iliakan Oct 15, 2017
ec243fb
Merge pull request #245 from lilifan/patch-1
iliakan Oct 15, 2017
24411a8
Merge pull request #244 from usernamehw/patch-2
iliakan Oct 15, 2017
00ad9b5
Update article.md
usernamehw Oct 15, 2017
b2869fe
Update task.md
usernamehw Oct 15, 2017
5b0e2ae
Update solution.md
usernamehw Oct 15, 2017
4e85f3a
Update solution.md
usernamehw Oct 15, 2017
2581e1d
Update task.md
usernamehw Oct 15, 2017
62ca575
Update solution.md
usernamehw Oct 15, 2017
b202d61
Update solution.md
usernamehw Oct 15, 2017
13719f8
Update solution.md
usernamehw Oct 15, 2017
844f832
Update task.md
usernamehw Oct 15, 2017
0d9af8a
Update solution.md
usernamehw Oct 15, 2017
f54bb0b
Remove extra word
bakesi Oct 16, 2017
82583be
minor
iliakan Oct 17, 2017
ccc0e93
Merge branch 'master' of https://github.com/iliakan/javascript-tutori…
iliakan Oct 17, 2017
4a9a6ab
Update article.md
YNataly Oct 18, 2017
38f4a7b
Update article.md
YNataly Oct 18, 2017
586a68c
it is syntactic sugar, not syntax
iselldonuts Oct 19, 2017
855c544
Minor spelling correction
beyondcompute Oct 20, 2017
0f386b1
Update article.md
usernamehw Oct 21, 2017
c2eea5d
Update article.md
usernamehw Oct 21, 2017
6a766c0
Update solution.md
usernamehw Oct 21, 2017
4490ce6
Update article.md
usernamehw Oct 21, 2017
9a3580e
Update article.md
usernamehw Oct 21, 2017
c0cf5a8
fixed typo
hadrysmateusz Oct 22, 2017
6d29e74
fixed typo in 1-endless-page
Oct 24, 2017
ae53c63
Update article.md
xterminal Oct 24, 2017
8159675
Update article.md
usernamehw Oct 24, 2017
a851ef6
Update article.md
usernamehw Oct 25, 2017
d04b6ac
Update article.md
usernamehw Oct 26, 2017
4bd0c6e
Update article.md
usernamehw Oct 26, 2017
dd6141f
Update article.md
usernamehw Oct 26, 2017
a5e3043
Update article.md
usernamehw Oct 28, 2017
62c8669
Update article.md
usernamehw Oct 30, 2017
4fbb92b
Fix "ReferenceError: calculator is not defined"
usernamehw Oct 30, 2017
ab94743
Update task.md
usernamehw Oct 30, 2017
3b4f96c
Update article.md
usernamehw Oct 30, 2017
b2605eb
Width/height mistype.
kudrautsau-m Oct 31, 2017
f6d630a
Update article.md
usernamehw Oct 31, 2017
3003233
Merge pull request #287 from usernamehw/patch-28
iliakan Nov 1, 2017
adbdd71
Merge pull request #285 from ponyborn/patch-1
iliakan Nov 1, 2017
a1a0060
Merge pull request #284 from usernamehw/patch-26
iliakan Nov 1, 2017
f1a90ac
Merge pull request #283 from usernamehw/patch-25
iliakan Nov 1, 2017
b7df8ec
Merge pull request #282 from usernamehw/patch-24
iliakan Nov 1, 2017
8977e93
Merge pull request #281 from usernamehw/patch-23
iliakan Nov 1, 2017
783530e
Merge pull request #280 from usernamehw/patch-22
iliakan Nov 1, 2017
f91d414
Merge pull request #279 from usernamehw/patch-21
iliakan Nov 1, 2017
8f9a0d7
Merge pull request #250 from usernamehw/patch-4
iliakan Nov 1, 2017
a61add9
Merge pull request #278 from usernamehw/patch-20
iliakan Nov 1, 2017
ef18a97
Merge pull request #277 from usernamehw/patch-19
iliakan Nov 1, 2017
8f49969
Merge pull request #275 from usernamehw/patch-18
iliakan Nov 1, 2017
ce3e1e9
Merge pull request #251 from usernamehw/patch-5
iliakan Nov 1, 2017
944f89c
Merge pull request #252 from usernamehw/patch-6
iliakan Nov 1, 2017
a7b3c5c
Merge pull request #253 from usernamehw/patch-7
iliakan Nov 1, 2017
f9e237e
Merge pull request #274 from usernamehw/patch-17
iliakan Nov 1, 2017
4aa190b
Merge pull request #273 from xterminal/patch-1
iliakan Nov 1, 2017
1c7557c
Merge pull request #272 from shihao7i/1-endless-page
iliakan Nov 1, 2017
6353874
Merge pull request #270 from ematte/patch-2
iliakan Nov 1, 2017
42ca672
Merge pull request #269 from usernamehw/patch-16
iliakan Nov 1, 2017
ecc4f6d
Merge pull request #268 from usernamehw/patch-15
iliakan Nov 1, 2017
0f0a844
Merge pull request #267 from usernamehw/patch-14
iliakan Nov 1, 2017
ff01c05
Merge pull request #266 from usernamehw/patch-13
iliakan Nov 1, 2017
0eab921
Merge pull request #265 from usernamehw/patch-12
iliakan Nov 1, 2017
5e8b968
Merge pull request #263 from beyondcompute/patch-2
iliakan Nov 1, 2017
19065c7
Merge pull request #262 from SlighTReturn/patch-1
iliakan Nov 1, 2017
ef797bf
Merge pull request #261 from YNataly/patch-5
iliakan Nov 1, 2017
0f0b5aa
Merge pull request #260 from YNataly/patch-4
iliakan Nov 1, 2017
9c4fb95
Merge pull request #259 from beksultan28/patch-1
iliakan Nov 1, 2017
2440ab7
Merge pull request #257 from usernamehw/patch-11
iliakan Nov 1, 2017
0832633
Merge pull request #256 from usernamehw/patch-10
iliakan Nov 1, 2017
10927ec
Merge pull request #255 from usernamehw/patch-9
iliakan Nov 1, 2017
b67884c
Merge pull request #254 from usernamehw/patch-8
iliakan Nov 1, 2017
973810d
fixes
iliakan Nov 1, 2017
0f1455d
Merge branch 'master' of https://github.com/iliakan/javascript-tutori…
iliakan Nov 1, 2017
0d81f75
Merge pull request #249 from usernamehw/patch-3
iliakan Nov 1, 2017
b2559f4
Update article.md
iliakan Nov 1, 2017
b890e7d
Typo
Bemerauld Nov 5, 2017
64b077f
Below instead of Above
Bemerauld Nov 5, 2017
cb26b55
Clarity for this
antonzabirko Nov 10, 2017
b103586
Merge pull request #294 from antonzabirko/patch-1
iliakan Nov 14, 2017
46d177f
Merge pull request #293 from Bemerauld/patch-1
iliakan Nov 14, 2017
7bfdc06
Merge pull request #291 from Bemerauld/patch-2
iliakan Nov 14, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions 1-js/01-getting-started/1-intro/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The browser has an embedded engine, sometimes it's also called a "JavaScript vir
Different engines have different "codenames", for example:

- [V8](https://en.wikipedia.org/wiki/V8_(JavaScript_engine)) -- in Chrome and Opera.
- [Gecko](https://en.wikipedia.org/wiki/Gecko_(software)) -- in Firefox.
- [SpiderMonkey](https://en.wikipedia.org/wiki/SpiderMonkey) -- in Firefox.
- ...There are other codenames like "Trident", "Chakra" for different versions of IE, "ChakraCore" for Microsoft Edge, "Nitro" and "SquirrelFish" for Safari etc.

The terms above are good to remember, because they are used in developer articles on the internet. We'll use them too. For instance, if "a feature X is supported by V8", then it probably works in Chrome and Opera.
Expand Down Expand Up @@ -108,7 +108,7 @@ Modern tools make the transpilation very fast and transparent, actually allowing

Examples of such languages:

- [CoffeeScript](http://coffeescript.org/) is a "syntax sugar" for JavaScript, it introduces shorter syntax, allowing to write more precise and clear code. Usually Ruby devs like it.
- [CoffeeScript](http://coffeescript.org/) is a "syntactic sugar" for JavaScript, it introduces shorter syntax, allowing to write more precise and clear code. Usually Ruby devs like it.
- [TypeScript](http://www.typescriptlang.org/) is concentrated on adding "strict data typing", to simplify development and support of complex systems. It is developed by Microsoft.
- [Dart](https://www.dartlang.org/) is a standalone language that has its own engine that runs in non-browser environments (like mobile apps). It was initially offered by Google as a replacement for JavaScript, but as of now, browsers require it to be transpiled to JavaScript just like the ones above.

Expand Down
137 changes: 137 additions & 0 deletions 1-js/02-first-steps/01-hello-world/article.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# Hello, world!

The tutorial that you're reading is about core JavaScript, which is platform-independent. Further on, you will learn Node.JS and other platforms that use it.

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 a webpage. For server-side environments, you can just execute it with a command like `"node my.js"` for Node.JS.


[cut]

## The "script" tag

JavaScript programs can be inserted in any part of an HTML document with the help of the `<script>` tag.

For instance:

```html run height=100
<!DOCTYPE HTML>
<html>

<body>

<p>Before the script...</p>

*!*
<script>
alert( 'Hello, world!' );
</script>
*/!*

<p>...After the script.</p>

</body>

</html>
```

```online
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.


## The modern markup

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>

: 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>&lt;script <u>language</u>=...&gt;</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.

Comments before and after scripts.
: In really ancient books and guides, one may find comments inside `<script>`, like this:

```html no-beautify
<script type="text/javascript"><!--
...
//--></script>
```

These comments were supposed to hide the code from an old browser that didn't know about a `<script>` tag. But all browsers born in the past 15+ years don't have any issues. We mention it here, because such comments serve as a sign. If you see that somewhere -- that code is probably really old and not worth looking into.


## External 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 the `src` attribute:

```html
<script src="/path/to/script.js"></script>
```

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"` in the current folder.

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>
```

To attach several scripts, use multiple tags:

```html
<script src="/js/script1.js"></script>
<script src="/js/script2.js"></script>
```

```smart
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).

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.
```

````warn header="If `src` is set, the script content is ignored."
A single `<script>` tag can't have both the `src` attribute and the code inside.

This won't work:

```html
<script *!*src*/!*="file.js">
alert(1); // the content is ignored, because src is set
</script>
```

We must choose: either it's an external `<script src="…">` or a regular `<script>` with code.

The example above can be split into two scripts to work:

```html
<script src="file.js"></script>
<script>
alert(1);
</script>
```
````

## Summary

- We can use a `<script>` tag to add JavaScript code to the page.
- The `type` and `language` attributes are not required.
- A script in an external file can be inserted with `<script src="path/to/script.js"></script>`.


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.
12 changes: 7 additions & 5 deletions 1-js/02-first-steps/04-variables/article.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Variables

Most of the time, a script needs to work with information. If it's an online-shop -- that's going to be the goods and a shopping cart. If it's a chat -- users, messages and so on.
Most of the time, a JavaScript application needs to work with information. Here are 2 examples:
1. An online-shop -- the information might include goods being sold and a shopping cart.
2. A chat application -- the information might include users, messages, and much more.

Variables are used to store the information.
Variables are used to store this information.

[cut]

Expand Down Expand Up @@ -296,7 +298,7 @@ Please name the variables sensibly. Take time to think if needed.

Variable naming is one of the most important and complex skills in programming. A quick glance at variable names can reveal which code is written by a beginner and which by an experienced developer.

In a real project, most of the time is spent on modifying and extending the existing code base, rather than writing something completely separate from the scratch. And when we return to the code after some time of doing something else, it's much easier to find information that is well-labelled. Or, in other words, when the variables have good names.
In a real project, most of the time is spent on modifying and extending the existing code base, rather than writing something completely separate from scratch. And when we return to the code after some time of doing something else, it's much easier to find information that is well-labelled. Or, in other words, when the variables have good names.

Please spend some time thinking about the right name for a variable before declaring it. That will repay you a lot.

Expand All @@ -305,14 +307,14 @@ Some good-to-follow rules are:
- Use human-readable names like `userName` or `shoppingCart`.
- Stay away from abbreviations or short names like `a`, `b`, `c`, unless you really know what you're doing.
- Make the name maximally descriptive and concise. Examples of bad names are `data` and `value`. Such a name says nothing. It is only ok to use them if it's exceptionally obvious from the context which data or value is meant.
- Agree on terms within the team and in your own mind. If a site visitor is called a "user" then we should name related variables like `currentUser` or `newUser`, but not `currentVisitor` or a `newManInTown`.
- Agree on terms within your team and in your own mind. If a site visitor is called a "user" then we should name related variables like `currentUser` or `newUser`, but not `currentVisitor` or a `newManInTown`.

Sounds simple? Indeed it is, but creating good descriptive-and-concise names in practice is not. Go for it.

```smart header="Reuse or create?"
And the last note. There are some lazy programmers who, instead of declaring a new variable, tend to reuse the existing ones.

As the result, the variable is like a box where people throw different things without changing the sticker. What is inside it now? Who knows... We need to come closer and check.
As a result, the variable is like a box where people throw different things without changing the sticker. What is inside it now? Who knows... We need to come closer and check.

Such a programmer saves a little bit on variable declaration, but loses ten times more on debugging the code.

Expand Down
2 changes: 1 addition & 1 deletion 1-js/02-first-steps/05-types/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ It supports two forms of syntax:
1. As an operator: `typeof x`.
2. Function style: `typeof(x)`.

In other words, it works both with the brackets or without them. The result is the same.
In other words, it works both with parentheses or without them. The result is the same.

The call to `typeof x` returns a string with the type name:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ undefined + 1 = NaN // (4)
```

1. The addition with a string `"" + 1` converts `1` to a string: `"" + 1 = "1"`, and then we have `"1" + 0`, the same rule is applied.
2. The substruction `"-"` (like most math operations) only works with numbers, it converts an empty string `""` to `0`.
2. The subtraction `"-"` (like most math operations) only works with numbers, it converts an empty string `""` to `0`.
3. `null` becomes `0` after the numeric conversion.
4. `undefined` becomes `NaN` after the numeric conversion.
18 changes: 9 additions & 9 deletions 1-js/02-first-steps/07-operators/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ alert( b ); // 4
alert( c ); // 4
```

Chained assignments evaluate from right to left. First the rightmost expression `2+2` is evaluated then assigned to the variables on the left: `c`, `b` and `a`. At the end, all variables share a single value.
Chained assignments evaluate from right to left. First the rightmost expression `2 + 2` is evaluated then assigned to the variables on the left: `c`, `b` and `a`. At the end, all variables share a single value.

````smart header="The assignment operator `\"=\"` returns a value"
An operator always returns a value. That's obvious for most of them like an addition `+` or a multiplication `*`. But the assignment operator follows that rule too.
Expand Down Expand Up @@ -281,7 +281,7 @@ let a = ++counter; // (*)
alert(a); // *!*2*/!*
```

Here in the line `(*)` the prefix call `++counter` increments `i` and returns the new value that is `2`. So the `alert` shows `2`.
Here in the line `(*)` the prefix call `++counter` increments `counter` and returns the new value that is `2`. So the `alert` shows `2`.

Now let's use the postfix form:

Expand All @@ -292,7 +292,7 @@ let a = counter++; // (*) changed ++counter to counter++
alert(a); // *!*1*/!*
```

In the line `(*)` the *postfix* form `counter++` also increments `i`, but returns the *old* value (prior to increment). So the `alert` shows `1`.
In the line `(*)` the *postfix* form `counter++` also increments `counter`, but returns the *old* value (prior to increment). So the `alert` shows `1`.

To summarize:

Expand Down Expand Up @@ -381,8 +381,8 @@ This notation can be shortened using operators `+=` and `*=`:

```js run
let n = 2;
n += 5; // now n=7 (same as n = n + 5)
n *= 2; // now n=14 (same as n = n * 2)
n += 5; // now n = 7 (same as n = n + 5)
n *= 2; // now n = 14 (same as n = n * 2)

alert( n ); // 14
```
Expand All @@ -409,18 +409,18 @@ For example:

```js run
*!*
let a = (1+2, 3+4);
let a = (1 + 2, 3 + 4);
*/!*

alert( a ); // 7 (the result of 3+4)
alert( a ); // 7 (the result of 3 + 4)
```

Here, the first expression `1+2` is evaluated, and its result is thrown away, then `3+4` is evaluated and returned as the result.
Here, the first expression `1 + 2` is evaluated, and its result is thrown away, then `3 + 4` is evaluated and returned as the result.

```smart header="Comma has a very low precedence"
Please note that the comma operator has very low precedence, lower than `=`, so parentheses are important in the example above.

Without them: `a=1+2,3+4` evaluates `+` first, summing the numbers into `a=3,7`, then the assignment operator `=` assigns `a=3`, and then the number after the comma `7` is not processed anyhow, so it's ignored.
Without them: `a = 1 + 2, 3 + 4` evaluates `+` first, summing the numbers into `a = 3, 7`, then the assignment operator `=` assigns `a = 3`, and then the number after the comma `7` is not processed anyhow, so it's ignored.
```

Why do we need such an operator which throws away everything except the last part?
Expand Down
2 changes: 1 addition & 1 deletion 1-js/02-first-steps/11-logical-operators/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ if (hour < 10 || hour > 18 || isWeekend) {

## OR seeks the first truthy value

The logic described above is somewhat classical. Now let's bring in the "extra" features of JavaScipt.
The logic described above is somewhat classical. Now let's bring in the "extra" features of JavaScript.

The extended algorithm works as follows.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ for (let i = 0; i < 5; i++) alert( i );

That can be easily deducted from the algorithm of `for`:

1. Execute once `i=0` before everything (begin).
2. Check the condition `i<5`
1. Execute once `i = 0` before everything (begin).
2. Check the condition `i < 5`
3. If `true` -- execute the loop body `alert(i)`, and then `i++`

The increment `i++` is separated from the condition check (2). That's just another statement.
Expand Down
4 changes: 2 additions & 2 deletions 1-js/02-first-steps/12-while-for/7-list-primes/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ importance: 3

An integer number greater than `1` is called a [prime](https://en.wikipedia.org/wiki/Prime_number) if it cannot be divided without a remainder by anything except `1` and itself.

In other words, `n>1` is a prime if it can't be evenly divided by anything except `1` and `n`.
In other words, `n > 1` is a prime if it can't be evenly divided by anything except `1` and `n`.

For example, `5` is a prime, because it cannot be divided without a remainder by `2`, `3` and `4`.

**Write the code which outputs prime numbers in the interval from `2` to `n`.**

For `n=10` the result will be `2,3,5,7`.
For `n = 10` the result will be `2,3,5,7`.

P.S. The code should work for any `n`, not be hard-tuned for any fixed value.
20 changes: 10 additions & 10 deletions 1-js/02-first-steps/12-while-for/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ while (condition) {

While the `condition` is `true`, the `code` from the loop body is executed.

For instance, the loop below outputs `i` while `i<3`:
For instance, the loop below outputs `i` while `i < 3`:

```js run
let i = 0;
Expand All @@ -37,7 +37,7 @@ If there were no `i++` in the example above, the loop would repeat (in theory) f

Any expression or a variable can be a loop condition, not just a comparison. They are evaluated and converted to boolean by `while`.

For instance, the shorter way to write `while (i!=0)` could be `while (i)`:
For instance, the shorter way to write `while (i != 0)` could be `while (i)`:

```js run
let i = 3;
Expand Down Expand Up @@ -108,8 +108,8 @@ Let's examine the `for` statement part by part:

| part | | |
|-------|----------|----------------------------------------------------------------------------|
| begin | `i=0` | Executes once upon entering the loop. |
| condition | `i<3`| Checked before every loop iteration, if fails the loop stops. |
| begin | `i = 0` | Executes once upon entering the loop. |
| condition | `i < 3`| Checked before every loop iteration, if fails the loop stops. |
| step| `i++` | Executes after the body on each iteration, but before the condition check. |
| body | `alert(i)`| Runs again and again while the condition is truthy |

Expand Down Expand Up @@ -188,11 +188,11 @@ We can also remove the `step` part:
let i = 0;

for (; i < 3;) {
alert( i );
alert( i++ );
}
```

The loop became identical to `while (i<3)`.
The loop became identical to `while (i < 3)`.

We can actually remove everything, thus creating an infinite loop:

Expand Down Expand Up @@ -239,7 +239,7 @@ The `continue` directive is a "lighter version" of `break`. It doesn't stop the

We can use it if we're done on the current iteration and would like to move on to the next.

The loop above uses `continue` to output only odd values:
The loop below uses `continue` to output only odd values:

```js run no-beautify
for (let i = 0; i < 10; i++) {
Expand Down Expand Up @@ -324,7 +324,7 @@ The ordinary `break` after `input` would only break the inner loop. That's not s

A *label* is an identifier with a colon before a loop:
```js
labelName: for(...) {
labelName: for (...) {
...
}
```
Expand Down Expand Up @@ -369,7 +369,7 @@ For example, it is impossible to do this:
```js
break label; // jumps to label? No.

label: for(...)
label: for (...)
```

The call to a `break/continue` is only possible from inside the loop, and the label must be somewhere upwards from the directive.
Expand All @@ -381,7 +381,7 @@ We covered 3 types of loops:

- `while` -- The condition is checked before each iteration.
- `do..while` -- The condition is checked after each iteration.
- `for(;;)` -- The condition is checked before each iteration, additional settings available.
- `for (;;)` -- The condition is checked before each iteration, additional settings available.

To make an "infinite" loop, usually the `while(true)` construct is used. Such a loop, just like any other, can be stopped with the `break` directive.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ function checkAge(age) {
}
```

Is there any difference in the bahavior of these two variants?
Is there any difference in the behavior of these two variants?
Loading