Skip to content

The old "var" - #477

Open
diogoosz wants to merge 1 commit into
javascript-tutorial:masterfrom
diogoosz:translate-old-var
Open

diogoosz wants to merge 1 commit into
javascript-tutorial:masterfrom
diogoosz:translate-old-var

Conversation

@diogoosz

@diogoosz diogoosz commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Tradução do artigo "The old var" para o português.

Conforme comentado na #1.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

*!*
alert(test); // ReferenceError: test is not defined
alert(test); // ReferenceError: test não está definido

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The translated error message here is not what the engine prints. Running this example shows ReferenceError: test is not defined, so readers will see different text from the comment. It also clashes with the SyntaxError messages in this same file (lines 96 and 234), which stay in English, and with the rest of the repo, which keeps is not defined.

Suggested change
alert(test); // ReferenceError: test não está definido
alert(test); // ReferenceError: test is not defined


sayHi();
alert(phrase); // ReferenceError: phrase is not defined
alert(phrase); // ReferenceError: phrase não está definido

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same problem as line 55: the engine prints ReferenceError: phrase is not defined, not translated text.

Suggested change
alert(phrase); // ReferenceError: phrase não está definido
alert(phrase); // ReferenceError: phrase is not defined


*!*+*/!*function() {
alert("Unary plus starts the expression");
alert("Operador unário de adição inicia a expressão");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Unary plus" means the unary + operator, not addition. "Operador unário de adição" gets the concept wrong. The repo already uses "mais unário" (see 99-js-misc/05-bigint).

Suggested change
alert("Operador unário de adição inicia a expressão");
alert("Operador mais unário inicia a expressão");

```

As we can see, `var` pierces through `if`, `for` or other code blocks. That's because a long time ago in JavaScript, blocks had no Lexical Environments, and `var` is a remnant of that.
Como podemos ver, `var` atravessa o `if`, o `for` ou outros blocos de código. Isso acontece porque, há muito tempo, no JavaScript os blocos não tinham Ambientes Léxicos, e `var` é um resquício disso.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Terminology does not match the repo. "Lexical Environment" stays in English throughout the tutorial (about 70 times, including the closure chapter this text refers back to). Writing "Ambientes Léxicos" here breaks the link with that chapter. Suggest: os blocos não tinham Lexical Environments.

Então, os parênteses em torno da função são um truque para mostrar ao JavaScript que a função é criada no contexto de outra expressão, e, portanto, é uma Expressão de Função: ela não precisa de nome e pode ser chamada imediatamente.

There exist other ways besides parentheses to tell JavaScript that we mean a Function Expression:
Existem outras formas, além dos parênteses, de dizer ao JavaScript que queremos dizer uma Expressão de Função:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This copies "we mean" too literally, and "dizer ... que queremos dizer" repeats the verb.

Suggested change
Existem outras formas, além dos parênteses, de dizer ao JavaScript que queremos dizer uma Expressão de Função:
Existem outras formas, além dos parênteses, de indicar ao JavaScript que se trata de uma Expressão de Função:


1. `var` variables have no block scope, their visibility is scoped to current function, or global, if declared outside function.
2. `var` declarations are processed at function start (script start for globals).
1. As variáveis `var` não têm escopo de bloco, sua visibilidade tem escopo na função atual, ou global, se declaradas fora de uma função.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"sua visibilidade tem escopo na função atual" reads awkwardly.

Suggested change
1. As variáveis `var` não têm escopo de bloco, sua visibilidade tem escopo na função atual, ou global, se declaradas fora de uma função.
1. As variáveis `var` não têm escopo de bloco: sua visibilidade fica restrita à função atual, ou é global, se declaradas fora de uma função.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants