Skip to content

Commit a5ff414

Browse files
authored
Merge pull request #6 from javascript-tutorial/sync-08734734
Sync with upstream @ 0873473
2 parents 7bfc789 + 38522bb commit a5ff414

File tree

125 files changed

+721
-665
lines changed

Some content is hidden

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

125 files changed

+721
-665
lines changed

1-js/01-getting-started/1-intro/article.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ Să vedem ce e atât de special la JavaScript, ce putem realiza cu el și ce alt
66

77
*JavaScript* a fost creat inițial pentru *"a da viață paginilor"*.
88

9+
<<<<<<< HEAD
910
În acest limbaj programele sunt numite *script-uri*(scripts). Acestea pot fi scrise direct în HTML și executate în mod automat pe măsură ce pagina se încarcă.
11+
=======
12+
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.
13+
>>>>>>> 08734734021aa128c13da2382fe8fa062677bb9f
1014
1115
Script-urile sunt furnizate și executate ca și text simplu. Ele nu au nevoie de pregătire specială sau de compilare pentru a rula.
1216

@@ -70,7 +74,11 @@ Exemplele acestor restricții sunt:
7074
Există mijloace prin care se poate interacționa cu camera/microfonul sau alte dispozitive, dar ele necesită permisiunea explicită a utilizatorului. Așadar o pagină pe care este activat JavaScript-ul nu ar putea activa o cameră web în mod viclean, și să privească împrejurimile și să trimită informații către [NSA](https://en.wikipedia.org/wiki/National_Security_Agency).
7175
- În general, diferite tab-uri/ferestre nu știu nimic unele despre celelalte. Câteodată acestea știu, de exemplu când o fereastră folosește JavaScript pentru a deschide cealaltă fereastră. Dar chiar și în acest caz, JavaScript nu poate accesa cealaltă fereastră dacă ambele ferestre vin de pe site-uri diferite (de la un domeniu, protocol sau port diferit).
7276

77+
<<<<<<< HEAD
7378
Acest lucru se numește "Same Origin Policy"(politica aceleiași origini). Pentru a lucra în jurul acesteia, *ambele pagini* trebuie să conțină un cod special JavaScript care să administreze schimbul de date.
79+
=======
80+
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.
81+
>>>>>>> 08734734021aa128c13da2382fe8fa062677bb9f
7482
7583
Limitarea este din nou pentru siguranța utilizatorului. O pagină de la `http://anysite.com` pe care un utilizator a deschis-o nu trebuie să poată accesa alt tab al browser-ului cu URL-ul `http://gmail.com` și să fure informații de acolo.
7684
- JavaScript poate cu ușurință să comunice pe net către server, de unde a venit pagina curentă. Dar abilitatea sa de a primi date de la alte site-uri/domenii este infirmată. Deși posibil, acesta necesită acord explicit(exprimat prin headere HTTP) din partea serverului de la distanță. Din nou, acestea sunt limitări de securitate.

1-js/02-first-steps/01-hello-world/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Hello, world!
22

3-
The tutorial that you're reading is about core JavaScript, which is platform-independent. Later on, you'll learn about Node.js and other platforms that use it.
3+
This part of the tutorial is about core JavaScript, the language itself. Later on, you'll learn about Node.js and other platforms that use it.
44

55
But we need a working environment to run our scripts and, since 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). We'll focus on JavaScript in the browser in the [next part](/ui) of the tutorial.
66

@@ -46,7 +46,7 @@ The `<script>` tag contains JavaScript code which is automatically executed when
4646
The `<script>` tag has a few attributes that are rarely used nowadays but can still be found in old code:
4747

4848
The `type` attribute: <code>&lt;script <u>type</u>=...&gt;</code>
49-
: The old HTML standard, HTML4, required a script to have a `type`. Usually it was `type="text/javascript"`. It's not required anymore. Also, the modern HTML standard, HTML5, 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 in another part of the tutorial.
49+
: The old HTML standard, HTML4, required a script to have a `type`. Usually it was `type="text/javascript"`. It's not required anymore. Also, the modern HTML standard, HTML5, 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 in another part of the tutorial.
5050

5151
The `language` attribute: <code>&lt;script <u>language</u>=...&gt;</code>
5252
: This attribute was meant to show the language of the script. This attribute no longer makes sense because JavaScript is the default language. There is no need to use it.

1-js/02-first-steps/04-variables/article.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ alert(message); // Hello world!
136136
```
137137
138138
```smart header="Functional languages"
139-
It's interesting to note that [functional](https://en.wikipedia.org/wiki/Functional_programming) programming languages, like [Scala](http://www.scala-lang.org/) or [Erlang](http://www.erlang.org/), forbid changing variable values.
139+
It's interesting to note that there exist [functional](https://en.wikipedia.org/wiki/Functional_programming) programming languages, like [Scala](http://www.scala-lang.org/) or [Erlang](http://www.erlang.org/) that forbid changing variable values.
140140
141141
In such languages, once the value is stored "in the box", it's there forever. If we need to store something else, the language forces us to create a new box (declare a new variable). We can't reuse the old one.
142142
@@ -182,7 +182,7 @@ let my-name; // hyphens '-' aren't allowed in the name
182182
Variables named `apple` and `AppLE` are two different variables.
183183
```
184184
185-
````smart header="Non-English letters are allowed, but not recommended"
185+
````smart header="Non-Latin letters are allowed, but not recommended"
186186
It is possible to use any language, including cyrillic letters or even hieroglyphs, like this:
187187
188188
```js
@@ -254,7 +254,7 @@ There is a widespread practice to use constants as aliases for difficult-to-reme
254254
255255
Such constants are named using capital letters and underscores.
256256
257-
Like this:
257+
For instance, let's make constants for colors in so-called "web" (hexadecimal) format:
258258
259259
```js run
260260
const COLOR_RED = "#F00";
@@ -290,7 +290,7 @@ In other words, capital-named constants are only used as aliases for "hard-coded
290290
291291
Talking about variables, there's one more extremely important thing.
292292
293-
Please name your variables sensibly. Take time to think about this.
293+
A variable name should have a clean, obvious meaning, describe the data that it stores.
294294
295295
Variable naming is one of the most important and complex skills in programming. A quick glance at variable names can reveal which code was written by a beginner versus an experienced developer.
296296

1-js/02-first-steps/05-types/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ The last three lines may need additional explanation:
226226

227227
## Summary
228228

229-
There are 7 basic types in JavaScript.
229+
There are 7 basic data types in JavaScript.
230230

231231
- `number` for numbers of any kind: integer or floating-point.
232232
- `string` for strings. A string may have one or more characters, there's no separate single-character type.

1-js/02-first-steps/08-comparison/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ Why does it dislike zero so much? Always false!
193193
We get these results because:
194194

195195
- Comparisons `(1)` and `(2)` return `false` because `undefined` gets converted to `NaN` and `NaN` is a special numeric value which returns `false` for all comparisons.
196-
- The equality check `(3)` returns `false` because `undefined` only equals `null` and no other value.
196+
- The equality check `(3)` returns `false` because `undefined` only equals `null`, `undefined`, and no other value.
197197

198198
### Evade problems
199199

1-js/02-first-steps/09-alert-prompt-confirm/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Interaction: alert, prompt, confirm
22

3-
This part of the tutorial aims to cover JavaScript "as is", without environment-specific tweaks.
3+
In this part of the tutorial we cover JavaScript language "as is", without environment-specific tweaks.
44

55
But we'll still be using the browser as our demo environment, so we should know at least a few of its user-interface functions. In this chapter, we'll get familiar with the browser functions `alert`, `prompt` and `confirm`.
66

1-js/02-first-steps/10-ifelse/article.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Sometimes, we need to perform different actions based on different conditions.
44

5-
To do that, we use the `if` statement and the conditional (ternary) operator which we will be referring to as the “question mark operator `?` for simplicity.
5+
To do that, we can use the `if` statement and the conditional operator `?`, that's also called a "question mark" operator.
66

77
## The "if" statement
88

@@ -103,7 +103,7 @@ In the code above, JavaScript first checks `year < 2015`. If that is falsy, it g
103103

104104
There can be more `else if` blocks. The final `else` is optional.
105105

106-
## Ternary operator '?'
106+
## Conditional operator '?'
107107

108108
Sometimes, we need to assign a variable depending on a condition.
109109

@@ -124,9 +124,9 @@ if (age > 18) {
124124
alert(accessAllowed);
125125
```
126126

127-
The so-called "ternary" or "question mark" operator lets us do that in a shorter and simpler way.
127+
The so-called "conditional" or "question mark" operator lets us do that in a shorter and simpler way.
128128

129-
The operator is represented by a question mark `?`. The formal term "ternary" means that the operator has three operands. It is actually the one and only operator in JavaScript which has that many.
129+
The operator is represented by a question mark `?`. Sometimes it's called "ternary", because the operator has three operands. It is actually the one and only operator in JavaScript which has that many.
130130

131131
The syntax is:
132132
```js
@@ -141,7 +141,7 @@ For example:
141141
let accessAllowed = (age > 18) ? true : false;
142142
```
143143

144-
Technically, we can omit the parentheses around `age > 18`. The question mark operator has a low precedence, so it executes after the comparison `>`.
144+
Technically, we can omit the parentheses around `age > 18`. The question mark operator has a low precedence, so it executes after the comparison `>`.
145145

146146
This example will do the same thing as the previous one:
147147

1-js/02-first-steps/11-logical-operators/article.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ The OR `||` operator does the following:
8484

8585
A value is returned in its original form, without the conversion.
8686

87-
In other words, a chain of OR `"||"` returns the first truthy value or the last one if no such value is found.
87+
In other words, a chain of OR `"||"` returns the first truthy value or the last one if no truthy value is found.
8888

8989
For instance:
9090

@@ -101,7 +101,7 @@ This leads to some interesting usage compared to a "pure, classical, boolean-onl
101101

102102
1. **Getting the first truthy value from a list of variables or expressions.**
103103

104-
Imagine we have several variables which can either contain data or be `null/undefined`. How can we find the first one with data?
104+
Imagine we have a list of variables which can either contain data or be `null/undefined`. How can we find the first one with data?
105105

106106
We can use OR `||`:
107107

@@ -143,7 +143,7 @@ This leads to some interesting usage compared to a "pure, classical, boolean-onl
143143
alert(x); // 1
144144
```
145145

146-
An assignment is a simple case. Other side effects can also be involved.
146+
An assignment is a simple case. There may be side effects, that won't show up if the evaluation doesn't reach them.
147147

148148
As we can see, such a use case is a "shorter way of doing `if`". The first operand is converted to boolean. If it's false, the second one is evaluated.
149149

1-js/02-first-steps/12-while-for/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ while (i) { // when i becomes 0, the condition becomes falsy, and the loop stops
4747
}
4848
```
4949

50-
````smart header="Brackets are not required for a single-line body"
51-
If the loop body has a single statement, we can omit the brackets `{…}`:
50+
````smart header="Curly braces are not required for a single-line body"
51+
If the loop body has a single statement, we can omit the curly braces `{…}`:
5252
5353
```js run
5454
let i = 3;

1-js/02-first-steps/14-function-basics/article.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ showMessage();
101101
alert( userName ); // *!*Bob*/!*, the value was modified by the function
102102
```
103103

104-
The outer variable is only used if there's no local one. So an occasional modification may happen if we forget `let`.
104+
The outer variable is only used if there's no local one.
105105

106106
If a same-named variable is declared inside the function then it *shadows* the outer one. For instance, in the code below the function uses the local `userName`. The outer one is ignored:
107107

@@ -128,7 +128,7 @@ Variables declared outside of any function, such as the outer `userName` in the
128128
129129
Global variables are visible from any function (unless shadowed by locals).
130130
131-
Usually, a function declares all variables specific to its task. Global variables only store project-level data, and it's important that these variables are accessible from anywhere. Modern code has few or no globals. Most variables reside in their functions.
131+
It's a good practice to minimize the use of global variables. Modern code has few or no globals. Most variables reside in their functions. Sometimes though, they can be useful to store project-level data.
132132
```
133133

134134
## Parameters
@@ -376,7 +376,7 @@ A few examples of breaking this rule:
376376
- `createForm` -- would be bad if it modifies the document, adding a form to it (should only create it and return).
377377
- `checkPermission` -- would be bad if it displays the `access granted/denied` message (should only perform the check and return the result).
378378

379-
These examples assume common meanings of prefixes. What they mean for you is determined by you and your team. Maybe it's pretty normal for your code to behave differently. But you should have a firm understanding of what a prefix means, what a prefixed function can and cannot do. All same-prefixed functions should obey the rules. And the team should share the knowledge.
379+
These examples assume common meanings of prefixes. You and your team are free to agree on other meanings, but usually they're not much different. In any case, you should have a firm understanding of what a prefix means, what a prefixed function can and cannot do. All same-prefixed functions should obey the rules. And the team should share the knowledge.
380380
```
381381

382382
```smart header="Ultrashort function names"

0 commit comments

Comments
 (0)