Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
translated tasks 5,6,7
  • Loading branch information
bogdanbacosca committed Mar 10, 2023
commit 85403e9128392313d4d817b0b4ca33d6ad88d59f
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
The result is **an error**.
Rezultatul este **o eroare**.

The function `sayHi` is declared inside the `if`, so it only lives inside it. There is no `sayHi` outside.
Funcția `sayHi` este declarată în interiorul lui `if`, deci trăiește doar în interiorul acestuia. Nu există `sayHi` în exterior.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
importance: 5

---
# Function in if
# Funcție în if

Look at the code. What will be the result of the call at the last line?
Priviți codul. Care va fi rezultatul apelului de la ultima linie?

```js run
let phrase = "Hello";
let phrase = "Bună ziua";

if (true) {
let user = "John";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
For the second parentheses to work, the first ones must return a function.
Pentru ca a doua paranteză să funcționeze, prima trebuie să returneze o funcție.

Like this:
Astfel:

```js run
function sum(a) {

return function(b) {
return a + b; // takes "a" from the outer lexical environment
return a + b; // preia "a" din mediul lexical exterior
};

}
Expand Down
8 changes: 4 additions & 4 deletions 1-js/06-advanced-functions/03-closure/6-closure-sum/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ importance: 4

---

# Sum with closures
# Însumare prin closure

Write function `sum` that works like this: `sum(a)(b) = a+b`.
Scrieți funcția `sum` care funcționează astfel: `sum(a)(b) = a+b`.

Yes, exactly this way, using double parentheses (not a mistype).
Da, exact în acest fel, folosind paranteze duble (nu este o greșeală de scriere).

For instance:
De exemplu:

```js
sum(1)(2) = 3
Expand Down
20 changes: 10 additions & 10 deletions 1-js/06-advanced-functions/03-closure/7-let-scope/solution.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The result is: **error**.
Rezultatul este: **eroare**.

Try running it:
Încercați să o rulați:

```js run
let x = 1;
Expand All @@ -15,20 +15,20 @@ function func() {
func();
```

In this example we can observe the peculiar difference between a "non-existing" and "uninitialized" variable.
În acest exemplu putem observa diferența specifică dintre o variabilă "inexistentă" și una "neinițializată".

As you may have read in the article [](info:closure), a variable starts in the "uninitialized" state from the moment when the execution enters a code block (or a function). And it stays uninitalized until the corresponding `let` statement.
După cum ați putut citi în articolul [](info:closure), o variabilă începe în starea "neinițializată" din momentul în care execuția intră într-un bloc de cod (sau într-o funcție). Și rămâne neinițializată până la instrucțiunea `let` corespunzătoare.

In other words, a variable technically exists, but can't be used before `let`.
Cu alte cuvinte, o variabilă există din punct de vedere tehnic, dar nu poate fi utilizată înainte de `let`.

The code above demonstrates it.
Codul de mai sus demonstrează acest lucru.

```js
function func() {
*!*
// the local variable x is known to the engine from the beginning of the function,
// but "uninitialized" (unusable) until let ("dead zone")
// hence the error
// variabila locală x este cunoscută de motor din începutul funcției,
// dar "neinițializată" (inutilizabilă) până la let ("zona moartă").
// de unde și eroarea
*/!*

console.log(x); // ReferenceError: Cannot access 'x' before initialization
Expand All @@ -37,4 +37,4 @@ function func() {
}
```

This zone of temporary unusability of a variable (from the beginning of the code block till `let`) is sometimes called the "dead zone".
Această zonă de neutilizare temporară a unei variabile (de la începutul blocului de cod până la `let`) se numește uneori "zonă moartă".
6 changes: 3 additions & 3 deletions 1-js/06-advanced-functions/03-closure/7-let-scope/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ importance: 4

---

# Is variable visible?
# Este variabila vizibilă?

What will be the result of this code?
Care va fi rezultatul acestui cod?

```js
let x = 1;
Expand All @@ -18,4 +18,4 @@ function func() {
func();
```

P.S. There's a pitfall in this task. The solution is not obvious.
P.S. Există o capcană în această sarcină. Soluția nu este evidentă.