Skip to content

Commit 0585fd5

Browse files
committed
merging all conflicts
2 parents dcd354d + 1dce5b7 commit 0585fd5

File tree

850 files changed

+23784
-12175
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

850 files changed

+23784
-12175
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
* text=auto eol=lf
2+
*.svg binary

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github: iliakan

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ sftp-config.json
2121
Thumbs.db
2222

2323

24+
/svgs
Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
# An Introduction to JavaScript
22

3-
Let's see what's so special about JavaScript, what we can achieve with it, and which other technologies play well with it.
3+
Let's see what's so special about JavaScript, what we can achieve with it, and what other technologies play well with it.
44

55
## What is JavaScript?
66

7-
*JavaScript* was initially created to *"make web pages alive"*.
7+
*JavaScript* was initially created to "make web pages alive".
88

99
The programs in this language are called *scripts*. They can be written right in a web page's HTML and run automatically as the page loads.
1010

1111
Scripts are provided and executed as plain text. They don't need special preparation or compilation to run.
1212

1313
In this aspect, JavaScript is very different from another language called [Java](https://en.wikipedia.org/wiki/Java_(programming_language)).
1414

15-
```smart header="Why <u>Java</u>Script?"
15+
```smart header="Why is it called <u>Java</u>Script?"
1616
When JavaScript was created, it initially had another name: "LiveScript". But Java was very popular at that time, so it was decided that positioning a new language as a "younger brother" of Java would help.
1717
1818
But as it evolved, JavaScript became a fully independent language with its own specification called [ECMAScript](http://en.wikipedia.org/wiki/ECMAScript), and now it has no relation to Java at all.
@@ -24,26 +24,26 @@ The browser has an embedded engine sometimes called a "JavaScript virtual machin
2424

2525
Different engines have different "codenames". For example:
2626

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

31-
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.
31+
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, Opera and Edge.
3232

3333
```smart header="How do engines work?"
3434
3535
Engines are complicated. But the basics are easy.
3636
3737
1. The engine (embedded if it's a browser) reads ("parses") the script.
38-
2. Then it converts ("compiles") the script to the machine language.
38+
2. Then it converts ("compiles") the script to machine code.
3939
3. And then the machine code runs, pretty fast.
4040
41-
The engine applies optimizations at each step of the process. It even watches the compiled script as it runs, analyzes the data that flows through it, and applies optimizations to the machine code based on that knowledge. When it's done, scripts run quite fast.
41+
The engine applies optimizations at each step of the process. It even watches the compiled script as it runs, analyzes the data that flows through it, and further optimizes the machine code based on that knowledge.
4242
```
4343

4444
## What can in-browser JavaScript do?
4545

46-
Modern JavaScript is a "safe" programming language. It does not provide low-level access to memory or CPU, because it was initially created for browsers which do not require it.
46+
Modern JavaScript is a "safe" programming language. It does not provide low-level access to memory or the CPU, because it was initially created for browsers which do not require it.
4747

4848
JavaScript's capabilities greatly depend on the environment it's running in. For instance, [Node.js](https://wikipedia.org/wiki/Node.js) supports functions that allow JavaScript to read/write arbitrary files, perform network requests, etc.
4949

@@ -59,25 +59,25 @@ For instance, in-browser JavaScript is able to:
5959

6060
## What CAN'T in-browser JavaScript do?
6161

62-
JavaScript's abilities in the browser are limited for the sake of the user's safety. The aim is to prevent an evil webpage from accessing private information or harming the user's data.
62+
JavaScript's abilities in the browser are limited to protect the user's safety. The aim is to prevent an evil webpage from accessing private information or harming the user's data.
6363

6464
Examples of such restrictions include:
6565

66-
- JavaScript on a webpage may not read/write arbitrary files on the hard disk, copy them or execute programs. It has no direct access to OS system functions.
66+
- JavaScript on a webpage may not read/write arbitrary files on the hard disk, copy them or execute programs. It has no direct access to OS functions.
6767

6868
Modern browsers allow it to work with files, but the access is limited and only provided if the user does certain actions, like "dropping" a file into a browser window or selecting it via an `<input>` tag.
6969

70-
There are ways to interact with camera/microphone and other devices, but they require a user's explicit permission. So a JavaScript-enabled page may not sneakily enable a web-camera, observe the surroundings and send the information to the [NSA](https://en.wikipedia.org/wiki/National_Security_Agency).
71-
- Different tabs/windows generally do not know about each other. Sometimes they do, for example when one window uses JavaScript to open the other one. But even in this case, JavaScript from one page may not access the other if they come from different sites (from a different domain, protocol or port).
70+
There are ways to interact with the camera/microphone and other devices, but they require a user's explicit permission. So a JavaScript-enabled page may not sneakily enable a web-camera, observe the surroundings and send the information to the [NSA](https://en.wikipedia.org/wiki/National_Security_Agency).
71+
- Different tabs/windows generally do not know about each other. Sometimes they do, for example when one window uses JavaScript to open the other one. But even in this case, JavaScript from one page may not access the other page if they come from different sites (from a different domain, protocol or port).
7272

73-
This is called the "Same Origin Policy". To work around that, *both pages* must agree for data exchange and contain a special JavaScript code that handles it. We'll cover that in the tutorial.
73+
This is called the "Same Origin Policy". To work around that, *both pages* must agree for data exchange and must contain special JavaScript code that handles it. We'll cover that in the tutorial.
7474

75-
This limitation is, again, for the user's safety. A page from `http://anysite.com` which a user has opened must not be able to access another browser tab with the URL `http://gmail.com` and steal information from there.
75+
This limitation is, again, for the user's safety. A page from `http://anysite.com` which a user has opened must not be able to access another browser tab with the URL `http://gmail.com`, for example, and steal information from there.
7676
- JavaScript can easily communicate over the net to the server where the current page came from. But its ability to receive data from other sites/domains is crippled. Though possible, it requires explicit agreement (expressed in HTTP headers) from the remote side. Once again, that's a safety limitation.
7777

7878
![](limitations.svg)
7979

80-
Such limits do not exist if JavaScript is used outside of the browser, for example on a server. Modern browsers also allow plugin/extensions which may ask for extended permissions.
80+
Such limitations do not exist if JavaScript is used outside of the browser, for example on a server. Modern browsers also allow plugins/extensions which may ask for extended permissions.
8181

8282
## What makes JavaScript unique?
8383

@@ -86,35 +86,37 @@ There are at least *three* great things about JavaScript:
8686
```compare
8787
+ Full integration with HTML/CSS.
8888
+ Simple things are done simply.
89-
+ Support by all major browsers and enabled by default.
89+
+ Supported by all major browsers and enabled by default.
9090
```
9191
JavaScript is the only browser technology that combines these three things.
9292

9393
That's what makes JavaScript unique. That's why it's the most widespread tool for creating browser interfaces.
9494

95-
While planning to learn a new technology, it's beneficial to check its perspectives. So let's move on to the modern trends affecting it, including new languages and browser abilities.
96-
95+
That said, JavaScript can be used to create servers, mobile applications, etc.
9796

9897
## Languages "over" JavaScript
9998

10099
The syntax of JavaScript does not suit everyone's needs. Different people want different features.
101100

102101
That's to be expected, because projects and requirements are different for everyone.
103102

104-
So recently a plethora of new languages appeared, which are *transpiled* (converted) to JavaScript before they run in the browser.
103+
So, recently a plethora of new languages appeared, which are *transpiled* (converted) to JavaScript before they run in the browser.
105104

106105
Modern tools make the transpilation very fast and transparent, actually allowing developers to code in another language and auto-converting it "under the hood".
107106

108107
Examples of such languages:
109108

110-
- [CoffeeScript](http://coffeescript.org/) is a "syntactic sugar" for JavaScript. It introduces shorter syntax, allowing us to write clearer and more precise code. Usually, Ruby devs like it.
111-
- [TypeScript](http://www.typescriptlang.org/) is concentrated on adding "strict data typing" to simplify the development and support of complex systems. It is developed by Microsoft.
112-
- [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.
109+
- [CoffeeScript](https://coffeescript.org/) is "syntactic sugar" for JavaScript. It introduces shorter syntax, allowing us to write clearer and more precise code. Usually, Ruby devs like it.
110+
- [TypeScript](https://www.typescriptlang.org/) is concentrated on adding "strict data typing" to simplify the development and support of complex systems. It is developed by Microsoft.
111+
- [Flow](https://flow.org/) also adds data typing, but in a different way. Developed by Facebook.
112+
- [Dart](https://www.dartlang.org/) is a standalone language that has its own engine that runs in non-browser environments (like mobile apps), but also can be transpiled to JavaScript. Developed by Google.
113+
- [Brython](https://brython.info/) is a Python transpiler to JavaScript that enables the writing of applications in pure Python without JavaScript.
114+
- [Kotlin](https://kotlinlang.org/docs/reference/js-overview.html) is a modern, concise and safe programming language that can target the browser or Node.
113115

114-
There are more. Of course, even if we use one of these languages, we should also know JavaScript to really understand what we're doing.
116+
There are more. Of course, even if we use one of these transpiled languages, we should also know JavaScript to really understand what we're doing.
115117

116118
## Summary
117119

118-
- JavaScript was initially created as a browser-only language, but is now used in many other environments as well.
119-
- Today, JavaScript has a unique position as the most widely-adopted browser language with full integration with HTML/CSS.
120+
- JavaScript was initially created as a browser-only language, but it is now used in many other environments as well.
121+
- Today, JavaScript has a unique position as the most widely-adopted browser language, fully integrated with HTML/CSS.
120122
- There are many languages that get "transpiled" to JavaScript and provide certain features. It is recommended to take a look at them, at least briefly, after mastering JavaScript.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
# Manuals and specifications
3+
4+
This book is a *tutorial*. It aims to help you gradually learn the language. But once you're familiar with the basics, you'll need other resources.
5+
6+
## Specification
7+
8+
[The ECMA-262 specification](https://www.ecma-international.org/publications/standards/Ecma-262.htm) contains the most in-depth, detailed and formalized information about JavaScript. It defines the language.
9+
10+
But being that formalized, it's difficult to understand at first. So if you need the most trustworthy source of information about the language details, the specification is the right place. But it's not for everyday use.
11+
12+
A new specification version is released every year. Between these releases, the latest specification draft is at <https://tc39.es/ecma262/>.
13+
14+
To read about new bleeding-edge features, including those that are "almost standard" (so-called "stage 3"), see proposals at <https://github.com/tc39/proposals>.
15+
16+
Also, if you're developing for the browser, then there are other specifications covered in the [second part](info:browser-environment) of the tutorial.
17+
18+
## Manuals
19+
20+
- **MDN (Mozilla) JavaScript Reference** is the main manual with examples and other information. It's great to get in-depth information about individual language functions, methods etc.
21+
22+
You can find it at <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference>.
23+
24+
Although, it's often best to use an internet search instead. Just use "MDN [term]" in the query, e.g. <https://google.com/search?q=MDN+parseInt> to search for the `parseInt` function.
25+
26+
## Compatibility tables
27+
28+
JavaScript is a developing language, new features get added regularly.
29+
30+
To see their support among browser-based and other engines, see:
31+
32+
- <https://caniuse.com> - per-feature tables of support, e.g. to see which engines support modern cryptography functions: <https://caniuse.com/#feat=cryptography>.
33+
- <https://kangax.github.io/compat-table> - a table with language features and engines that support those or don't support.
34+
35+
All these resources are useful in real-life development, as they contain valuable information about language details, their support, etc.
36+
37+
Please remember them (or this page) for the cases when you need in-depth information about a particular feature.

1-js/01-getting-started/2-code-editors/article.md renamed to 1-js/01-getting-started/3-code-editors/article.md

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@ An IDE loads the project (which can be many files), allows navigation between fi
1212

1313
If you haven't selected an IDE yet, consider the following options:
1414

15-
- [WebStorm](http://www.jetbrains.com/webstorm/) for frontend development. The same company offers other editors for other languages (paid).
16-
- [Netbeans](http://netbeans.org/) (free).
15+
- [Visual Studio Code](https://code.visualstudio.com/) (cross-platform, free).
16+
- [WebStorm](https://www.jetbrains.com/webstorm/) (cross-platform, paid).
1717

18-
All of these IDEs are cross-platform.
18+
For Windows, there's also "Visual Studio", not to be confused with "Visual Studio Code". "Visual Studio" is a paid and mighty Windows-only editor, well-suited for the .NET platform. It's also good at JavaScript. There's also a free version [Visual Studio Community](https://www.visualstudio.com/vs/community/).
1919

20-
For Windows, there's also "Visual Studio", not to be confused with "Visual Studio Code." "Visual Studio" is a paid and mighty Windows-only editor, well-suited for the .NET platform. A free version of it is called [Visual Studio Community](https://www.visualstudio.com/vs/community/).
21-
22-
Many IDEs are paid but have a trial period. Their cost is usually negligible compared to a qualified developer's salary, so just choose the best one for you.
20+
Many IDEs are paid, but have a trial period. Their cost is usually negligible compared to a qualified developer's salary, so just choose the best one for you.
2321

2422
## Lightweight editors
2523

@@ -31,22 +29,11 @@ The main difference between a "lightweight editor" and an "IDE" is that an IDE w
3129

3230
In practice, lightweight editors may have a lot of plugins including directory-level syntax analyzers and autocompleters, so there's no strict border between a lightweight editor and an IDE.
3331

34-
The following options deserve your attention:
32+
There are many options, for instance:
3533

36-
- [Visual Studio Code](https://code.visualstudio.com/) (cross-platform, free) also has many IDE-like features.
37-
- [Atom](https://atom.io/) (cross-platform, free).
38-
- [Sublime Text](http://www.sublimetext.com) (cross-platform, shareware).
34+
- [Sublime Text](https://www.sublimetext.com/) (cross-platform, shareware).
3935
- [Notepad++](https://notepad-plus-plus.org/) (Windows, free).
40-
- [Vim](http://www.vim.org/) and [Emacs](https://www.gnu.org/software/emacs/) are also cool if you know how to use them.
41-
42-
## My favorites
43-
44-
The personal preference of the author is to have both an IDE for projects and a lightweight editor for quick and easy file editing.
45-
46-
I'm using:
47-
48-
- As an IDE for JS -- [WebStorm](http://www.jetbrains.com/webstorm/) (I switch to one of the other JetBrains offerings when using other languages)
49-
- As a lightweight editor -- [Sublime Text](http://www.sublimetext.com) or [Atom](https://atom.io/).
36+
- [Vim](https://www.vim.org/) and [Emacs](https://www.gnu.org/software/emacs/) are also cool if you know how to use them.
5037

5138
## Let's not argue
5239

@@ -55,3 +42,8 @@ The editors in the lists above are those that either I or my friends whom I cons
5542
There are other great editors in our big world. Please choose the one you like the most.
5643

5744
The choice of an editor, like any other tool, is individual and depends on your projects, habits, and personal preferences.
45+
46+
The author's personal opinion:
47+
48+
- I'd use [Visual Studio Code](https://code.visualstudio.com/) if I develop mostly frontend.
49+
- Otherwise, if it's mostly another language/platform and partially frontend, then consider other editors, such as XCode (Mac), Visual Studio (Windows) or Jetbrains family (Webstorm, PHPStorm, RubyMine etc, depending on the language).
-105 KB
Binary file not shown.
Binary file not shown.

1-js/01-getting-started/3-devtools/article.md renamed to 1-js/01-getting-started/4-devtools/article.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,15 @@ The exact look of developer tools depends on your version of Chrome. It changes
2929
- Here we can see the red-colored error message. In this case, the script contains an unknown "lalala" command.
3030
- On the right, there is a clickable link to the source `bug.html:12` with the line number where the error has occurred.
3131

32-
Below the error message, there is a blue `>` symbol. It marks a "command line" where we can type JavaScript commands. Press `key:Enter` to run them (`key:Shift+Enter` to input multi-line commands).
32+
Below the error message, there is a blue `>` symbol. It marks a "command line" where we can type JavaScript commands. Press `key:Enter` to run them.
3333

3434
Now we can see errors, and that's enough for a start. We'll come back to developer tools later and cover debugging more in-depth in the chapter <info:debugging-chrome>.
3535

36+
```smart header="Multi-line input"
37+
Usually, when we put a line of code into the console, and then press `key:Enter`, it executes.
38+
39+
To insert multiple lines, press `key:Shift+Enter`. This way one can enter long fragments of JavaScript code.
40+
```
3641

3742
## Firefox, Edge, and others
3843

@@ -50,12 +55,6 @@ Open Preferences and go to the "Advanced" pane. There's a checkbox at the bottom
5055

5156
Now `key:Cmd+Opt+C` can toggle the console. Also, note that the new top menu item named "Develop" has appeared. It has many commands and options.
5257

53-
## Multi-line input
54-
55-
Usually, when we put a line of code into the console, and then press `key:Enter`, it executes.
56-
57-
To insert multiple lines, press `key:Shift+Enter`.
58-
5958
## Summary
6059

6160
- Developer tools allow us to see errors, run commands, examine variables, and much more.
107 KB
Loading
Loading
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<body>
5+
6+
<script>
7+
alert( "I'm JavaScript!" );
8+
</script>
9+
10+
</body>
11+
12+
</html>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
[html src="index.html"]

0 commit comments

Comments
 (0)