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/02-first-steps/14-function-basics/article.md
+15-15Lines changed: 15 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,36 +1,36 @@
1
-
# Functions
1
+
# Funções
2
2
3
-
Quite often we need to perform a similar action in many places of the script.
3
+
Muitas vezes nós precisamos realizar uma ação semelhante em muitos lugares do script.
4
4
5
-
For example, we need to show a nice-looking message when a visitor logs in, logs out and maybe somewhere else.
5
+
Por exemplo, precisamos mostrar uma boa mensagem quando um usuário efetua login, efetua logout e talvez em outro lugar.
6
6
7
-
Functions are the main "building blocks" of the program. They allow the code to be called many times without repetition.
7
+
Funções são os principais "building blocks" do programa. Elas permitem que o código sejam chamados muitas vezes sem repetição.
8
8
9
-
We've already seen examples of built-in functions, like`alert(message)`, `prompt(message, default)`and`confirm(question)`. But we can create functions of our own as well.
9
+
Nós já vimos exemplos de built-in functions, como`alert(message)`, `prompt(message, default)`e`confirm(question)`. Mas nós podemos criar funções próprias também.
10
10
11
11
## Function Declaration
12
12
13
-
To create a function we can use a*function declaration*.
13
+
Para criarmos uma função podemos usar uma*function declaration*.
14
14
15
-
It looks like this:
15
+
Se parece assim:
16
16
17
17
```js
18
18
functionshowMessage() {
19
-
alert( 'Hello everyone!' );
19
+
alert( 'Olá a todos!' );
20
20
}
21
21
```
22
22
23
-
The `function`keyword goes first, then goes the *name of the function*, then a list of *parameters* between the parentheses (empty in the example above) 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 (vazio no exemplo acima) e finalmente o código da função, também chamado de "o corpo da função", entre chaves.
24
24
25
25

26
26
27
-
Our new function can be called by its name: `showMessage()`.
27
+
Nossa nova função pode ser chamada pelo seu nome: `showMessage()`.
28
28
29
-
For instance:
29
+
Por exemplo:
30
30
31
31
```js run
32
32
functionshowMessage() {
33
-
alert( 'Hello everyone!' );
33
+
alert( 'Olá a todos!' );
34
34
}
35
35
36
36
*!*
@@ -39,11 +39,11 @@ showMessage();
39
39
*/!*
40
40
```
41
41
42
-
The call`showMessage()`executes the code of the function. Here we will see the message two times.
42
+
A chamada`showMessage()`executa o código da função. Aqui vemos a mensagem duas vezes.
43
43
44
-
This example clearly demonstrates one of the main purposes of functions: to avoid code duplication.
44
+
Este exemplo demonstra claramente um dos principais objetivos das funções: evitar código duplicado.
45
45
46
-
If we ever need to change the message or the way it is shown, it's enough to modify the code in one place: the function which outputs it.
46
+
Se precisarmos mudar a mensagem ou a maneira que ela é mostrada, basta modificar o código em um só lugar: a função que gera isso.
0 commit comments