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
+1-7Lines changed: 1 addition & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,15 +24,9 @@ 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
28
27
-[V8](https://en.wikipedia.org/wiki/V8_(JavaScript_engine)) -- no Chrome e no Opera.
29
28
-[SpiderMonkey](https://en.wikipedia.org/wiki/SpiderMonkey) -- no Firefox.
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
29
+
- ...Há outros codinomes como "Chakra" para o IE, "JavaScriptCore", "Nitro" e "SquirrelFish" para Safari, etc.
36
30
37
31
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: 0 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,11 +8,7 @@ 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
12
11
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
+9-45Lines changed: 9 additions & 45 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,11 +46,7 @@ alert(3 +
46
46
+2);
47
47
```
48
48
49
-
<<<<<<< HEAD
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
49
+
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 aí seria incorreto. E neste caso isso funciona como pretendido.
54
50
55
51
**Mas há situações em que o JavaScript "falha" em assumir um ponto e vírgula onde ele é realmente necessário.**
56
52
@@ -65,63 +61,31 @@ alert("Hello");
65
61
[1, 2].forEach(alert);
66
62
```
67
63
68
-
<<<<<<< HEAD
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`.
64
+
Não há necessidade de pensar sobre o significado dos parênteses `[]` e também do `forEach`. Nós vamos estudá-los mais tarde. Por enquanto, apenas lembre-se do resultado da execução do código: ele mostra `Hello`, depois `1`, e depois` 2`.
70
65
71
-
Agora, vamos adicionar um `alert` antes do código e * não * terminá-lo com um ponto e vírgula:
72
-
73
-
```js run no-beautify
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`:
66
+
Agora, vamos remover o ponto e vírgula depois do `alert`:
79
67
80
68
```js run no-beautify
81
69
alert("Hello")
82
-
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c
83
70
84
71
[1, 2].forEach(alert);
85
72
```
86
73
87
-
<<<<<<< HEAD
88
-
Agora, se nós executarmos o código, apenas o primeiro `alert` é mostrado e então temos um erro!
89
-
90
-
Mas tudo está bem novamente se adicionarmos um ponto e vírgula após `alert`:
91
-
```js run
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
96
-
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.
74
+
A diferença em comparação com o código acima é de apenas um caractere: o ponto e vírgula da primeira linha se foi.
98
75
99
-
<<<<<<< HEAD
100
-
Agora temos a mensagem "Tudo bem agora" seguida por "1" e "2".
101
-
102
-
103
-
O erro na variante sem ponto e vírgula ocorre porque o JavaScript não assume um ponto e vírgula antes dos colchetes `[...]`.
104
-
105
-
Portanto, como o ponto e vírgula não é inserido automaticamente, o código no primeiro exemplo é tratado como uma única instrução. Veja como o mecanismo vê isso:
106
-
107
-
```js run no-beautify
108
-
alert("Haverá um erro")[1, 2].forEach(alert)
109
-
```
76
+
Se nós executarmos esse código, apenas o primeiro `Hello` é mostrado (e então há um erro, você pode precisar de abrir a consola para o ver). Já não existem mais números.
110
77
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.
78
+
Isso ocorre porque o JavaScript não assume um ponto e vírgula antes dos colchetes `[...]`. Portanto, o código no último exemplo é tratado como uma única instrução.
114
79
115
-
Here's how the engine sees it:
80
+
Veja como o mecanismo vê isso:
116
81
117
82
```js run no-beautify
118
83
alert("Hello")[1, 2].forEach(alert);
119
84
```
120
85
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.
86
+
Parece estranho, não? Tal fusão neste caso é completamente errada. Nós precisamos de colocar um ponto e vírgula depois de `alert` para o código funcionar corretamente.
122
87
123
-
This can happen in other situations also.
124
-
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c
88
+
Isso também pode acontecer em outras situações.
125
89
````
126
90
127
91
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/15-function-basics/article.md
+2-14Lines changed: 2 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,19 +20,11 @@ function showMessage() {
20
20
}
21
21
```
22
22
23
-
<<<<<<< HEAD
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.
25
-
26
-
```js
27
-
functionname(parameters) {
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.
23
+
A palavra-chave `function` vem primeiro, depois vem o *nome da função*, e uma lista de *parâmetros* entre os parêntesis (separados por vírgulas, vazia no exemplo acima, veremos exemplos mais tarde) e finalmente o código da função, também chamado de "o corpo da função", entre chaves.
Copy file name to clipboardExpand all lines: 1-js/04-object-basics/09-object-toprimitive/article.md
-25Lines changed: 0 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,9 +3,6 @@
3
3
4
4
What happens when objects are added `obj1 + obj2`, subtracted `obj1 - obj2` or printed using `alert(obj)`?
5
5
6
-
<<<<<<< HEAD
7
-
There are special methods in objects that do the conversion.
8
-
=======
9
6
JavaScript doesn't exactly allow to customize how operators work on objects. Unlike some other programming languages, such as Ruby or C++, we can't implement a special object method to handle an addition (or other operators).
10
7
11
8
In case of such operations, objects are auto-converted to primitives, and then the operation is carried out over these primitives and results in a primitive value.
@@ -24,7 +21,6 @@ We have two purposes:
24
21
2. There are exceptions, where such operations are possible and look good. E.g. subtracting or comparing dates (`Date` objects). We'll come across them later.
25
22
26
23
## Conversion rules
27
-
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c
28
24
29
25
In the chapter <info:type-conversions> we've seen the rules for numeric, string and boolean conversions of primitives. But we left a gap for objects. Now, as we know about methods and symbols it becomes possible to close it.
30
26
@@ -34,23 +30,11 @@ The numeric conversion happens when we subtract objects or apply mathematical fu
34
30
35
31
As for the string conversion -- it usually happens when we output an object like `alert(obj)` and in similar contexts.
36
32
37
-
<<<<<<< HEAD
38
-
## ToPrimitive
39
-
40
-
When an object is used in the context where a primitive is required, for instance, in an `alert` or mathematical operations, it's converted to a primitive value using the `ToPrimitive` algorithm ([specification](https://tc39.github.io/ecma262/#sec-toprimitive)).
41
-
42
-
That algorithm allows us to customize the conversion using a special object method.
43
-
44
-
Depending on the context, the conversion has a so-called "hint".
45
-
46
-
There are three variants:
47
-
=======
48
33
We can fine-tune string and numeric conversion, using special object methods.
49
34
50
35
There are three variants of type conversion, that happen in various situations.
51
36
52
37
They're called "hints", as described in the [specification](https://tc39.github.io/ecma262/#sec-toprimitive):
53
-
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c
54
38
55
39
`"string"`
56
40
: When an operation expects a string, for object-to-string conversions, like `alert`:
@@ -117,12 +101,8 @@ Let's start from the first method. There's a built-in symbol named `Symbol.toPri
117
101
118
102
```js
119
103
obj[Symbol.toPrimitive] = function(hint) {
120
-
<<<<<<< HEAD
121
-
// return a primitive value
122
-
=======
123
104
// here goes the code to convert this object to a primitive
In the browser, independant top-level scope also exists for each `<script type="module">`:
111
-
=======
112
101
In the browser, if we talk about HTML pages, independent top-level scope also exists for each `<script type="module">`.
113
102
114
103
Here are two scripts on the same page, both `type="module"`. They don't see each other's top-level variables:
115
-
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c
116
104
117
105
```html run
118
106
<scripttype="module">
@@ -127,17 +115,13 @@ Here are two scripts on the same page, both `type="module"`. They don't see each
127
115
</script>
128
116
```
129
117
130
-
<<<<<<< HEAD
131
-
If we really need to make a "global" in-browser variable, we can explicitly assign it to `window` and access as `window.user`. But that's an exception requiring a good reason.
132
-
=======
133
118
```smart
134
119
In the browser, we can make a variable window-level global by explicitly assigning it to a `window` property, e.g. `window.user = "John"`.
135
120
136
121
Then all scripts will see it, both with `type="module"` and without it.
137
122
138
123
That said, making such global variables is frowned upon. Please try to avoid them.
139
124
```
140
-
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c
141
125
142
126
### A module code is evaluated only the first time when imported
143
127
@@ -164,11 +148,7 @@ import `./alert.js`; // Module is evaluated!
164
148
import`./alert.js`; // (nothing)
165
149
```
166
150
167
-
<<<<<<< HEAD
168
-
In practice, top-level module code is mostly used for initialization. We create data structures, pre-fill them, and if we want something to be reusable -- export it.
169
-
=======
170
151
The second import shows nothing, because the module has already been evaluated.
171
-
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c
172
152
173
153
There's a rule: top-level module code should be used for initialization, creation of module-specific internal data structures. If we need to make something callable multiple times - we should export it as a function, like we did with `sayHi` above.
174
154
@@ -202,13 +182,9 @@ alert(admin.name); // Pete
202
182
*/!*
203
183
```
204
184
205
-
<<<<<<< HEAD
206
-
So, let's reiterate -- the module is executed only once. Exports are generated, and then they are shared between importers, so if something changes the `admin` object, other modules will see that .
207
-
=======
208
185
As you can see, when `1.js` changes the `name` property in the imported `admin`, then `2.js` can see the new `admin.name`.
209
186
210
187
That's exactly because the module is executed only once. Exports are generated, and then they are shared between importers, so if something changes the `admin` object, other modules will see that.
211
-
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c
212
188
213
189
**Such behavior is actually very convenient, because it allows us to *configure* modules.**
214
190
@@ -230,29 +206,19 @@ export function sayHi() {
230
206
}
231
207
```
232
208
233
-
<<<<<<< HEAD
234
-
Now, in `init.js`, the first script of our app, we set `admin.name`. Then everyone will see it, including calls made from inside `admin.js` itself:
235
-
=======
236
209
Here, `admin.js` exports the `config` object (initially empty, but may have default properties too).
237
210
238
211
Then in `init.js`, the first script of our app, we import `config` from it and set `config.user`:
239
-
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c
240
212
241
213
```js
242
214
// 📁 init.js
243
215
import {config} from'./admin.js';
244
216
config.user="Pete";
245
217
```
246
218
247
-
<<<<<<< HEAD
248
-
```js
249
-
// 📁 other.js
250
-
import {admin, sayHi} from'./admin.js';
251
-
=======
252
219
...Now the module `admin.js` is configured.
253
220
254
221
Further importers can call it, and it correctly shows the current user:
0 commit comments