Skip to content

Commit c55e153

Browse files
authored
Translate local variables and outer variables
1 parent 90a5d1b commit c55e153

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

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

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -47,88 +47,88 @@ Se precisarmos mudar a mensagem ou a maneira que ela é mostrada, basta modifica
4747

4848
## Variáveis locais
4949

50-
A variable declared inside a function is only visible inside that function.
50+
Uma variável declarada dentro de uma função é apenas visível dentro dessa função.
5151

52-
For example:
52+
Por exemplo:
5353

5454
```js run
5555
function showMessage() {
5656
*!*
57-
let message = "Hello, I'm JavaScript!"; // local variable
57+
let message = "Olá, Eu sou JavaScript!"; // variável local
5858
*/!*
5959

6060
alert( message );
6161
}
6262

63-
showMessage(); // Hello, I'm JavaScript!
63+
showMessage(); // Olá, Eu sou JavaScript!
6464

65-
alert( message ); // <-- Error! The variable is local to the function
65+
alert( message ); // <-- Erro! A variável é local para a função
6666
```
6767

68-
## Outer variables
68+
## Variáveis externas
6969

70-
A function can access an outer variable as well, for example:
70+
Uma função também pode acessar uma variável externa, por exemplo:
7171

7272
```js run no-beautify
7373
let *!*userName*/!* = 'John';
7474

7575
function showMessage() {
76-
let message = 'Hello, ' + *!*userName*/!*;
76+
let message = 'Olá, ' + *!*userName*/!*;
7777
alert(message);
7878
}
7979

80-
showMessage(); // Hello, John
80+
showMessage(); // Olá, John
8181
```
8282

83-
The function has full access to the outer variable. It can modify it as well.
83+
A função tem acesso total à variável externa. Pode modificá-la também.
8484

85-
For instance:
85+
Por exemplo:
8686

8787
```js run
8888
let *!*userName*/!* = 'John';
8989

9090
function showMessage() {
91-
*!*userName*/!* = "Bob"; // (1) changed the outer variable
91+
*!*userName*/!* = "Bob"; // (1) mudou a variável externa
9292

93-
let message = 'Hello, ' + *!*userName*/!*;
93+
let message = 'Olá, ' + *!*userName*/!*;
9494
alert(message);
9595
}
9696

97-
alert( userName ); // *!*John*/!* before the function call
97+
alert( userName ); // *!*John*/!* antes da chamada da função
9898

9999
showMessage();
100100

101-
alert( userName ); // *!*Bob*/!*, the value was modified by the function
101+
alert( userName ); // *!*Bob*/!*, o valor foi modificado pela função
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+
A variável externa é apenas usada se não existir uma local. Então, uma modificação ocasional pode acontencer se esquercermos do `let`.
105105

106-
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:
106+
Se uma variável com o mesmo nome é declarada dentro da função, então ela *shadows* a externa. Por exemplo, no código abaixo, a função usa o `userName` local. O exterior é ignorado:
107107

108108
```js run
109109
let userName = 'John';
110110

111111
function showMessage() {
112112
*!*
113-
let userName = "Bob"; // declare a local variable
113+
let userName = "Bob"; // declara uma variável local
114114
*/!*
115115

116-
let message = 'Hello, ' + userName; // *!*Bob*/!*
116+
let message = 'Olá, ' + userName; // *!*Bob*/!*
117117
alert(message);
118118
}
119119

120-
// the function will create and use its own userName
120+
// a função criará e usará seu próprio userName
121121
showMessage();
122122

123-
alert( userName ); // *!*John*/!*, unchanged, the function did not access the outer variable
123+
alert( userName ); // *!*John*/!*, inalterado, a função não acessou a variável externa
124124
```
125125

126-
```smart header="Global variables"
127-
Variables declared outside of any function, such as the outer `userName` in the code above, are called *global*.
126+
```smart header="Variáveis globais"
127+
Variáveis declaradas fora de qualquer função, como o `userName` externo no código acima, são chamados de *globais*.
128128
129-
Global variables are visible from any function (unless shadowed by locals).
129+
Variáveis globais são visíveis por qualquer função (a não ser que sejam sombreadas pelas locais).
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+
Normalmente, uma função declara todas as variáveis específicas de sua tarefa. As variáveis globais armazenam apenas dados em nível de projeto e é importante que essas variáveis sejam acessíveis de qualquer lugar. Código moderno tem poucos ou nenhum globais. A maioria das variáveis reside em suas funções.
132132
```
133133

134134
## Parameters

0 commit comments

Comments
 (0)