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
Copy file name to clipboardExpand all lines: 1-js/01-getting-started/1-intro/article.md
+6Lines changed: 6 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,9 +24,15 @@ O navegador tem um interpretador(motor) incorporado, às vezes chamado de "máqu
24
24
25
25
Interpretadores diferentes têm "codinomes" diferentes. Por exemplo:
26
26
27
+
<<<<<<< HEAD
27
28
-[V8](https://en.wikipedia.org/wiki/V8_(JavaScript_engine)) -- no Chrome e no Opera.
28
29
-[SpiderMonkey](https://en.wikipedia.org/wiki/SpiderMonkey) -- no Firefox.
29
30
- ...Há outros codinomes como "Chakra" para o IE, "ChakraCore" para Microsoft Edge, "Nitro" e "SquirrelFish" para Safari, etc.
31
+
=======
32
+
-[V8](https://en.wikipedia.org/wiki/V8_(JavaScript_engine)) -- in Chrome and Opera.
33
+
-[SpiderMonkey](https://en.wikipedia.org/wiki/SpiderMonkey) -- in Firefox.
34
+
- ...There are other codenames like "Chakra" for IE, "JavaScriptCore", "Nitro" and "SquirrelFish" for Safari, etc.
35
+
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c
30
36
31
37
Os termos acima são bons para lembrar, pois são usados em artigos de desenvolvedores na internet. Vamos usá-los também. Por exemplo, se "um recurso X é suportado pelo V8", então ele provavelmente funciona no Chrome e no Opera.
Copy file name to clipboardExpand all lines: 1-js/01-getting-started/4-devtools/article.md
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,11 @@ Para que possamos visualizar erros e obter muitas outras informações úteis so
8
8
9
9
A maioria dos desenvolvedores escolhem o Chrome ou o Firefox para o desenvolvimento porque esses navegadores têm as melhores ferramentas de desenvolvedor. Outros navegadores também fornecem ferramentas de desenvolvedor, às vezes com recursos especiais, mas geralmente estão jogando "catch-up" no Chrome ou Firefox. Assim, a maioria dos desenvolvedores tem um navegador "favorito" e muda para outros se um problema é específico do navegador.
10
10
11
+
<<<<<<< HEAD
11
12
As ferramentas do desenvolvedor são potentes; elas têm muitos recursos. Para começar, vamos aprender como as abrir, olhar para erros e executar comandos JavaScript.
13
+
=======
14
+
Developer tools are potent; they have many features. To start, we'll learn how to open them, look at errors, and run JavaScript commands.
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/02-structure/article.md
+36-4Lines changed: 36 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,7 +46,11 @@ alert(3 +
46
46
+2);
47
47
```
48
48
49
+
<<<<<<< HEAD
49
50
O código produz `6` porque o Javascript não insere pontos e virgulas aqui. É intuitivamente óbvio que se a linha termina com um sinal de mais `"+"`, então é uma "expressão incompleta", logo o ponto e vírgula não é necessário. E neste caso isso funciona como pretendido.
51
+
=======
52
+
The code outputs `6` because JavaScript does not insert semicolons here. It is intuitively obvious that if the line ends with a plus `"+"`, then it is an "incomplete expression", so a semicolon there would be incorrect. And in this case, that works as intended.
53
+
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c
50
54
51
55
**Mas há situações em que o JavaScript "falha" em assumir um ponto e vírgula onde ele é realmente necessário.**
52
56
@@ -56,28 +60,43 @@ Erros que ocorrem em tais casos são bastante difíceis de encontrar e corrigir.
56
60
Se você está curioso para ver um exemplo concreto de tal erro, verifique este código:
57
61
58
62
```js run
59
-
[1, 2].forEach(alert)
63
+
alert("Hello");
64
+
65
+
[1, 2].forEach(alert);
60
66
```
61
67
68
+
<<<<<<< HEAD
62
69
Não há necessidade de pensar sobre o significado dos parênteses `[]` e `forEach` ainda. Nós vamos estudá-los mais tarde. Por enquanto, apenas lembre-se que o resultado do código: mostra `1` e depois` 2`.
63
70
64
71
Agora, vamos adicionar um `alert` antes do código e * não * terminá-lo com um ponto e vírgula:
65
72
66
73
```js run no-beautify
67
74
alert("Haverá um erro")
75
+
=======
76
+
No need to think about the meaning of the brackets `[]` and `forEach` yet. We'll study them later. For now, just remember the result of running the code: it shows `Hello`, then `1`, then `2`.
77
+
78
+
Now let's remove the semicolon after the `alert`:
79
+
80
+
```js run no-beautify
81
+
alert("Hello")
82
+
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c
68
83
69
-
[1, 2].forEach(alert)
84
+
[1, 2].forEach(alert);
70
85
```
71
86
87
+
<<<<<<< HEAD
72
88
Agora, se nós executarmos o código, apenas o primeiro `alert` é mostrado e então temos um erro!
73
89
74
90
Mas tudo está bem novamente se adicionarmos um ponto e vírgula após `alert`:
75
91
```js run
76
92
alert("Tudo bem agora");
93
+
=======
94
+
The difference compared to the code above is only one character: the semicolon at the end of the first line is gone.
95
+
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c
77
96
78
-
[1, 2].forEach(alert)
79
-
```
97
+
If we run this code, only the first `Hello` shows (and there's an error, you may need to open the console to see it). There are no numbers any more.
80
98
99
+
<<<<<<< HEAD
81
100
Agora temos a mensagem "Tudo bem agora" seguida por "1" e "2".
82
101
83
102
@@ -90,6 +109,19 @@ alert("Haverá um erro")[1, 2].forEach(alert)
90
109
```
91
110
92
111
Mas devem ser duas declarações separadas, não uma. Tal fusão neste caso é completamente errado, daí o erro. Isso pode acontecer em outras situações.
112
+
=======
113
+
That's because JavaScript does not assume a semicolon before square brackets `[...]`. So, the code in the last example is treated as a single statement.
114
+
115
+
Here's how the engine sees it:
116
+
117
+
```js run no-beautify
118
+
alert("Hello")[1, 2].forEach(alert);
119
+
```
120
+
121
+
Looks weird, right? Such merging in this case is just wrong. We need to put a semicolon after `alert` for the code to work correctly.
122
+
123
+
This can happen in other situations also.
124
+
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c
93
125
````
94
126
95
127
Recomendamos colocar ponto e vírgula entre as frases, mesmo que estejam separadas por novas linhas. Esta regra é amplamente adotada pela comunidade. Vamos notar mais uma vez -- *é possível* deixar de fora os pontos e vírgulas na maior parte do tempo. Mas é mais seguro -- especialmente para um iniciante -- usá-los.
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/05-types/article.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -64,7 +64,7 @@ Os valores numéricos especiais pertencem formalmente ao tipo "número". Claro q
64
64
65
65
Veremos mais sobre como trabalhar com números no capítulo <info:number>.
66
66
67
-
## BigInt
67
+
## BigInt [#bigint-type]
68
68
69
69
In JavaScript, the "number" type cannot represent integer values larger than <code>(2<sup>53</sup>-1)</code> (that's `9007199254740991`), or less than <code>-(2<sup>53</sup>-1)</code> for negatives. It's a technical limitation caused by their internal representation.
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/15-function-basics/article.md
+43-18Lines changed: 43 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,11 +20,19 @@ function showMessage() {
20
20
}
21
21
```
22
22
23
+
<<<<<<< HEAD
23
24
A palavra-chave `function` vem primeiro, depois vem o *nome da função*, e uma lista de *parâmetros* entre os parêntesis (vazio no exemplo acima) e finalmente o código da função, também chamado de "o corpo da função", entre chaves.
24
25
25
26
```js
26
27
functionname(parameters) {
27
28
...corpo...
29
+
=======
30
+
The `function` keyword goes first, then goes the *name of the function*, then a list of *parameters* between the parentheses (comma-separated, emptyintheexampleabove, we'll see examples later) and finally the code of the function, also named "the function body", between curly braces.
31
+
32
+
```js
33
+
function name(parameter1, parameter2, ... parameterN) {
34
+
...body...
35
+
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c
28
36
}
29
37
```
30
38
@@ -137,26 +145,23 @@ It's a good practice to minimize the use of global variables. Modern code has fe
137
145
138
146
## Parameters
139
147
140
-
We can pass arbitrary data to functions using parameters (also called *function arguments*) .
148
+
We can pass arbitrary data to functions using parameters.
141
149
142
150
In the example below, the function has two parameters: `from` and `text`.
143
151
144
152
```js run
145
-
functionshowMessage(*!*from, text*/!*) { //arguments:from, text
153
+
function showMessage(*!*from, text*/!*) { // parameters: from, text
When the function is called in lines `(*)` and `(**)`, the given values are copied to local variables `from` and `text`. Then the function uses them.
156
162
157
163
Here's one more example: we have a variable `from` and pass it to the function. Please note: the function changes `from`, but the change is not seen outside, because a function always gets a copy of the value:
When a value is passed as a function parameter, it's also called an *argument*.
184
+
185
+
In other words, to put these terms straight:
186
+
187
+
- A parameter is the variable listed inside the parentheses in the function declaration (it's a declaration time term)
188
+
- An argument is the value that is passed to the function when it is called (it's a call time term).
189
+
190
+
We declare functions listing their parameters, then call them passing arguments.
191
+
192
+
In the example above, one might say: "the function `sayMessage` is declared with two parameters, then called with two arguments: `from` and `"Hello"`".
193
+
194
+
178
195
## Default values
179
196
180
-
If a parameter is not provided, then its value becomes `undefined`.
197
+
If a function is called, but an argument is not provided, then the corresponding value becomes `undefined`.
181
198
182
199
For instance, the aforementioned function `showMessage(from, text)` can be called with a single argument:
183
200
184
201
```js
185
202
showMessage("Ann");
186
203
```
187
204
205
+
<<<<<<< HEAD
188
206
That's not an error. Such a call would output `"Ann: undefined"`. There's no `text`, so it's assumed that `text ===undefined`.
207
+
=======
208
+
That's not an error. Such a call would output `"*Ann*: undefined"`. As the value for `text` isn't passed, it becomes `undefined`.
209
+
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c
189
210
190
-
If we want to use a "default" `text` in this case, then we can specify it after`=`:
211
+
We can specify the so-called "default" (to use if omitted) value for a parameter in the function declaration, using`=`:
191
212
192
213
```js run
193
214
functionshowMessage(from, *!*text="no text given"*/!*) {
@@ -211,19 +232,23 @@ function showMessage(from, text = anotherFunction()) {
211
232
```smart header="Evaluation of default parameters"
212
233
In JavaScript, a default parameter is evaluated every time the function is called without the respective parameter.
213
234
214
-
In the example above, `anotherFunction()` is called every time `showMessage()` is called without the `text` parameter.
235
+
In the example above, `anotherFunction()` isn't called at all, if the `text` parameter is provided.
236
+
237
+
On the other hand, it's independently called every time when `text` is missing.
215
238
```
216
239
217
240
### Alternative default parameters
218
241
219
-
Sometimes it makes sense to set default values for parameters not in the function declaration, but at a later stage, during its execution.
242
+
Sometimes it makes sense to assign default values for parameters not in the function declaration, but at a later stage.
220
243
221
-
To check for an omitted parameter, we can compare it with `undefined`:
244
+
We can check if the parameter is passed during the function execution, by comparing it with `undefined`:
222
245
223
246
```js run
224
247
function showMessage(text) {
248
+
// ...
249
+
225
250
*!*
226
-
if (text ===undefined) {
251
+
if (text ===undefined) {// if the parameter is missing
227
252
text ='empty message';
228
253
}
229
254
*/!*
@@ -234,21 +259,21 @@ function showMessage(text) {
234
259
showMessage(); // empty message
235
260
```
236
261
237
-
...Or we could use the `||` operator:
262
+
...Or we could use the `??` operator:
238
263
239
264
```js
240
-
// if text parameter is omitted or "" is passed, set it to 'empty'
241
265
functionshowMessage(text) {
266
+
// if text is undefined or otherwise falsy, set it to 'empty'
242
267
text = text ||'empty';
243
268
...
244
269
}
245
270
```
246
271
247
-
Modern JavaScript engines support the [nullish coalescing operator](info:nullish-coalescing-operator) `??`, it's better when falsy values, such as `0`, are considered regular:
272
+
Modern JavaScript engines support the [nullish coalescing operator](info:nullish-coalescing-operator) `??`, it's better when most falsy values, such as `0`, should be considered "normal":
248
273
249
274
```js run
250
-
// if there's no "count" parameter, show "unknown"
251
275
functionshowCount(count) {
276
+
// if count is undefined or null, show "unknown"
252
277
alert(count ??"unknown");
253
278
}
254
279
@@ -411,7 +436,7 @@ Functions that are used *very often* sometimes have ultrashort names.
411
436
412
437
For example, the [jQuery](http://jquery.com) framework defines a function with `$`. The [Lodash](http://lodash.com/) library has its core function named `_`.
413
438
414
-
These are exceptions. Generally functions names should be concise and descriptive.
439
+
These are exceptions. Generally function names should be concise and descriptive.
0 commit comments