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: 03_functions.md
+12-47Lines changed: 12 additions & 47 deletions
Original file line number
Diff line number
Diff line change
@@ -2,44 +2,29 @@
2
2
3
3
{{quote {author: "Donald Knuth", chapter: true}
4
4
5
-
People think that computer science is the art of geniuses but the
6
-
actual reality is the opposite, just many people doing things that
7
-
build on each other, like a wall of mini stones.
5
+
As pessoas pensam que Ciência da Computação é a arte de gênios. Na realidade é o oposto, são várias pessoas fazendo coisas que dependem uma das outras, como um muro de pequenas pedras.
8
6
9
7
quote}}
10
8
11
9
{{index "Knuth, Donald"}}
12
10
13
-
{{figure {url: "img/chapter_picture_3.jpg", alt: "Picture of fern leaves with a fractal shape", chapter: framed}}}
11
+
{{figure {url: "img/chapter_picture_3.jpg", alt: "Foto de folhas de samambaia com um formato fractal", chapter: framed}}}
14
12
15
13
{{index function, [code, "structure of"]}}
16
14
17
-
Functions are the bread and butter of JavaScript programming. The
18
-
concept of wrapping a piece of program in a value has many uses. It
19
-
gives us a way to structure larger programs, to reduce repetition, to
20
-
associate names with subprograms, and to isolate these subprograms
21
-
from each other.
15
+
Funções são o pão e manteira da programação JavaScript. O conceito deencapsular um pedaço de um programa em um valor tem muitos usos. Issonôs dá um caminho para estruturas grandes programas, reduzir repetições, associar nomes com subprogramas, e isolar estes subprogramas uns dos outro.
22
16
23
-
The most obvious application of functions is defining new
24
-
((vocabulary)). Creating new words in prose is usually bad style. But
25
-
in programming, it is indispensable.
17
+
A aplicação mais óbvia das funções é quando queremos definir novos vocabulários. Criar novas palavras no nosso dia a dia geralmente não é uma boa ideia, porém em programação é indispensável.
26
18
27
19
{{index abstraction, vocabulary}}
28
20
29
-
Typical adult English speakers have some 20,000 words in their
30
-
vocabulary. Few programming languages come with 20,000 commands built
31
-
in. And the vocabulary that _is_ available tends to be more precisely
32
-
defined, and thus less flexible, than in human language. Therefore, we
33
-
usually _have_ to introduce new concepts to avoid repeating ourselves
34
-
too much.
21
+
Um adulto típico tem por volta de 20.000 palavras em seu vocabulário. Apenas algumas linguagens de programação possuem 20.000 conceitos embutidos, sendo que o vocabulário que se _tem_ disponível tende a ser bem definido e, por isso, menos flexível do que a linguagem usada por humanos. Por isso, normalmente _temos_ que adicionar conceitos do nosso próprio vocabulário para evitar repetição.
A function definition is a regular binding where the value of the
41
-
binding is a function. For example, this code defines `square` to
42
-
refer to a function that produces the square of a given number:
27
+
Uma definição de função nada mais é do que uma definição normal de uma variável, na qual o valor recebido pela variável é uma função. Por exemplo, o código a seguir define uma variável `square` que se refere a uma função que retorna o quadrado do número dado:
A function is created with an expression that starts with the keyword
57
-
`function`. Functions have a set of _((parameter))s_ (in this case,
58
-
only `x`) and a _body_, which contains the statements that are to be
59
-
executed when the function is called. The function body of a function
60
-
created this way must always be wrapped in braces, even when it
61
-
consists of only a single ((statement)).
41
+
Uma função é criada por meio de uma expressão que se inicia com a palavra-chave `function`. Funções podem receber uma série de parâmetros (nesse caso, somente `x`) e um _corpo_, contendo as declarações que serão executadas quando a função for invocada. O corpo da função deve estar sempre envolvido por chaves, mesmo quando for formado por apenas uma simples declaração (como no exemplo anterior).
62
42
63
43
{{index "power example"}}
64
44
65
-
A function can have multiple parameters or no parameters at all. In
66
-
the following example, `makeNoise` does not list any parameter names,
67
-
whereas `power` lists two:
45
+
Uma função pode receber múltiplos parâmetros ou nenhum parâmetro. No exemplo a seguir, `makeNoise` não recebe nenhum parâmetro, enquanto `power` recebe dois:
Some functions produce a value, such as `power` and `square`, and some
92
-
don't, such as `makeNoise`, whose only result is a ((side effect)). A
93
-
`return` statement determines the value the function returns. When
94
-
control comes across such a statement, it immediately jumps out of the
95
-
current function and gives the returned value to the code that called
96
-
the function. A `return` keyword without an expression after it will
97
-
cause the function to return `undefined`. Functions that don't have a
98
-
`return` statement at all, such as `makeNoise`, similarly return
99
-
`undefined`.
69
+
Algumas funções produzem um valor, como as funções `power` e `square` acima, e outras não, como no exemplo de `makeNoise`, que produz apenas um “efeito colateral”. A declaração `return` é usada para determinar o valor de retorno da função. Quando o controle de execução interpreta essa declaração, ele sai imediatamente do contexto da função atual e disponibiliza o valor retornado para o código que invocou a função. A palavra-chave `return` sem uma expressão após, irá fazer com que o retorno da função seja `undefined`. Funções que não possuem `return` declarado, retornam `undefined` da mesma forma.
Parameters to a function behave like regular bindings, but their
104
-
initial values are given by the _caller_ of the function, not the code
105
-
in the function itself.
73
+
Os parâmetros de uma função comportam-se como variáveis regulares. Seu valor inicial é informado por quem invocou a função e não pelo código da função em si.
Each binding has a _((scope))_, which is the part of the program
113
-
in which the binding is visible. For bindings defined outside of any
114
-
function or block, the scope is the whole program—you can refer to
115
-
such bindings wherever you want. These are called _global_.
80
+
Cada ligação tem um escopo, no qual é parte de um programada em que a ligação é visível. Para ligações definidas fora de qualquer função ou bloco, o escopo é o programa inteiro, voçê pode referenciar estas ligações onde você quiser. Ele são chamados de _global_.
0 commit comments