Skip to content

Commit 084120c

Browse files
Trabalhando em Funcoes/Definindo uma funcao/Ligacoes e escopos
1 parent c9e61f0 commit 084120c

File tree

1 file changed

+12
-47
lines changed

1 file changed

+12
-47
lines changed

03_functions.md

Lines changed: 12 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,29 @@
22

33
{{quote {author: "Donald Knuth", chapter: true}
44

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.
86

97
quote}}
108

119
{{index "Knuth, Donald"}}
1210

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}}}
1412

1513
{{index function, [code, "structure of"]}}
1614

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.
2216

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.
2618

2719
{{index abstraction, vocabulary}}
2820

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.
3522

36-
## Defining a function
23+
## Definindo uma função
3724

3825
{{index "square example", [function, definition], [binding, definition]}}
3926

40-
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:
4328

4429
```
4530
const square = function(x) {
@@ -53,18 +38,11 @@ console.log(square(12));
5338
{{indexsee "curly braces", braces}}
5439
{{index [braces, "function body"], block, [syntax, function], "function keyword", [function, body], [function, "as value"], [parentheses, arguments]}}
5540

56-
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).
6242

6343
{{index "power example"}}
6444

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:
6846

6947
```
7048
const makeNoise = function() {
@@ -88,31 +66,18 @@ console.log(power(2, 10));
8866

8967
{{index "return value", "return keyword", undefined}}
9068

91-
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.
10070

10171
{{index parameter, [function, application], [binding, "from parameter"]}}
10272

103-
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.
10674

10775
## Bindings and scopes
10876

10977
{{indexsee "top-level scope", "global scope"}}
11078
{{index "var keyword", "global scope", [binding, global], [binding, "scope of"]}}
11179

112-
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_.
11681

11782
{{index "local scope", [binding, local]}}
11883

0 commit comments

Comments
 (0)