You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 which other technologies play well with it.
4
4
5
5
## What is JavaScript?
6
6
7
-
*JavaScript* was initially created to *"make webpages alive"*.
7
+
*JavaScript* was initially created to *"make web pages alive"*.
8
8
9
-
The programs in this language are called *scripts*. They can be written right in the HTML and execute automatically as the page loads.
9
+
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.
10
10
11
-
Scripts are provided and executed as a plain text. They don't need a special preparation or a compilation to run.
11
+
Scripts are provided and executed as plain text. They don't need special preparation or compilation to run.
12
12
13
-
In this aspect, JavaScript is very different from another language called [Java](http://en.wikipedia.org/wiki/Java).
13
+
In this aspect, JavaScript is very different from another language called [Java](https://en.wikipedia.org/wiki/Java_(programming_language)).
14
14
15
-
```smart header="Why <u>Java</u>Script?"
16
-
When JavaScript was created, it initially had another name: "LiveScript". But Java language was very popular at that time, so it was decided that positioning a new language as a "younger brother" of Java would help.
15
+
```smart header="Why is it called <u>Java</u>Script?"
16
+
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.
17
17
18
-
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.
18
+
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.
19
19
```
20
20
21
-
At present, JavaScript can execute not only in the browser, but also on the server, or actually on any device where there exists a special program called [the JavaScript engine](https://en.wikipedia.org/wiki/JavaScript_engine).
21
+
Today, JavaScript can execute not only in the browser, but also on the server, or actually on any device that has a special program called [the JavaScript engine](https://en.wikipedia.org/wiki/JavaScript_engine).
22
22
23
-
The browser has an embedded engine, sometimes it's also called a "JavaScript virtual machine".
23
+
The browser has an embedded engine sometimes called a "JavaScript virtual machine".
24
24
25
-
Different engines have different "codenames", for example:
25
+
Different engines have different "codenames". For example:
26
26
27
27
-[V8](https://en.wikipedia.org/wiki/V8_(JavaScript_engine)) -- in Chrome and Opera.
28
28
-[SpiderMonkey](https://en.wikipedia.org/wiki/SpiderMonkey) -- in Firefox.
29
-
- ...There are other codenames like "Trident", "Chakra" for different versions of IE, "ChakraCore" for Microsoft Edge, "Nitro" and "SquirrelFish" for Safari etc.
29
+
- ...There are other codenames like "Trident" and "Chakra" for different versions of IE, "ChakraCore" for Microsoft Edge, "Nitro" and "SquirrelFish" for Safari, etc.
30
30
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 and Opera.
32
32
33
33
```smart header="How do engines work?"
34
34
@@ -38,16 +38,16 @@ Engines are complicated. But the basics are easy.
38
38
2. Then it converts ("compiles") the script to the machine language.
39
39
3. And then the machine code runs, pretty fast.
40
40
41
-
The engine applies optimizations on every stage 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. At the end, scripts are 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.
42
42
```
43
43
44
44
## What can in-browser JavaScript do?
45
45
46
-
The 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 CPU, because it was initially created for browsers which do not require it.
47
47
48
-
The capabilities greatly depend on the environment that runs JavaScript. For instance, [Node.JS](https://wikipedia.org/wiki/Node.js) supports functions that allow JavaScript to read/write arbitrary files, perform network requests etc.
48
+
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.
49
49
50
-
In-browser JavaScript can do everything related to webpage manipulation, interaction with the user and the webserver.
50
+
In-browser JavaScript can do everything related to webpage manipulation, interaction with the user, and the webserver.
51
51
52
52
For instance, in-browser JavaScript is able to:
53
53
@@ -61,7 +61,7 @@ For instance, in-browser JavaScript is able to:
61
61
62
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.
63
63
64
-
The examples of such restrictions are:
64
+
Examples of such restrictions include:
65
65
66
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.
67
67
@@ -70,31 +70,29 @@ The examples of such restrictions are:
70
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
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).
72
72
73
-
This is called the "Same Origin Policy". To work around that, *both pages* must contain a special JavaScript code that handles data exchange.
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.
74
74
75
-
The limitation is again for 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.
76
-
- 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 safety limitations.
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.
76
+
- 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.
77
77
78
-

78
+

79
79
80
-
Such limits do not exist if JavaScript is used outside of the browser, for example on a server. Modern browsers also allow installing plugin/extensions which may get extended permissions.
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.
81
81
82
82
## What makes JavaScript unique?
83
83
84
84
There are at least *three* great things about JavaScript:
85
85
86
86
```compare
87
87
+ Full integration with HTML/CSS.
88
-
+ Simple things done simply.
89
-
+ Supported by all major browsers and enabled by default.
88
+
+ Simple things are done simply.
89
+
+ Support by all major browsers and enabled by default.
90
90
```
91
+
JavaScript is the only browser technology that combines these three things.
91
92
92
-
Combined, these three things exist only in JavaScript and no other browser technology.
93
-
94
-
That's what makes JavaScript unique. That's why it's the most widespread tool to create browser interfaces.
95
-
96
-
While planning to learn a new technology, it's beneficial to check its perspectives. So let's move on to the modern trends that include new languages and browser abilities.
93
+
That's what makes JavaScript unique. That's why it's the most widespread tool for creating browser interfaces.
97
94
95
+
That said, JavaScript also allows to create servers, mobile applications, etc.
98
96
99
97
## Languages "over" JavaScript
100
98
@@ -104,18 +102,19 @@ That's to be expected, because projects and requirements are different for every
104
102
105
103
So recently a plethora of new languages appeared, which are *transpiled* (converted) to JavaScript before they run in the browser.
106
104
107
-
Modern tools make the transpilation very fast and transparent, actually allowing developers to code in another language and autoconverting it "under the hood".
105
+
Modern tools make the transpilation very fast and transparent, actually allowing developers to code in another language and auto-converting it "under the hood".
108
106
109
107
Examples of such languages:
110
108
111
-
-[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.
112
-
-[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.
113
-
-[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](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.
110
+
-[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.
111
+
-[Flow](http://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.
114
113
115
-
There are more. Of course even if we use one of those languages, we should also know JavaScript, to really understand what we're doing.
114
+
There are more. Of course, even if we use one of transpiled languages, we should also know JavaScript to really understand what we're doing.
116
115
117
116
## Summary
118
117
119
-
- JavaScript was initially created as a browser-only language, but now it is used in many other environments as well.
120
-
-At this moment, JavaScript has a unique position as the most widely-adopted browser language with full integration with HTML/CSS.
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.
121
120
- 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.
0 commit comments