diff --git a/1-js/02-first-steps/04-variables/1-hello-variables/solution.md b/1-js/02-first-steps/04-variables/1-hello-variables/solution.md index 9249e1c84..9c0166829 100644 --- a/1-js/02-first-steps/04-variables/1-hello-variables/solution.md +++ b/1-js/02-first-steps/04-variables/1-hello-variables/solution.md @@ -1,7 +1,7 @@ -In the code below, each line corresponds to the item in the task list. +În codul de mai jos, fiecare linie corespunde cu articolul din lista de sarcini. ```js run -let admin, name; // can declare two variables at once +let admin, name; // putem declara două variabile deodată name = "John"; @@ -10,3 +10,4 @@ admin = name; alert( admin ); // "John" ``` + diff --git a/1-js/02-first-steps/04-variables/1-hello-variables/task.md b/1-js/02-first-steps/04-variables/1-hello-variables/task.md index 84f009e8c..b17adfead 100644 --- a/1-js/02-first-steps/04-variables/1-hello-variables/task.md +++ b/1-js/02-first-steps/04-variables/1-hello-variables/task.md @@ -2,9 +2,9 @@ importance: 2 --- -# Working with variables +# Lucrând cu variabile -1. Declare two variables: `admin` and `name`. -2. Assign the value `"John"` to `name`. -3. Copy the value from `name` to `admin`. -4. Show the value of `admin` using `alert` (must output "John"). +1. Declară două variabile: `admin` și `name`. +2. Atribuie valoarea `"John"` la `name`. +3. Copiază valoarea de la `name` la `admin`. +4. Arată valoarea lui `admin` folosind `alert` (trebuie să iasă "John"). diff --git a/1-js/02-first-steps/04-variables/2-declare-variables/solution.md b/1-js/02-first-steps/04-variables/2-declare-variables/solution.md index 392f4e26f..3b22bdbe3 100644 --- a/1-js/02-first-steps/04-variables/2-declare-variables/solution.md +++ b/1-js/02-first-steps/04-variables/2-declare-variables/solution.md @@ -1,21 +1,21 @@ -## The variable for our planet +## Variabila pentru planeta noastră -That's simple: +Este simplu: ```js -let ourPlanetName = "Earth"; +let ourPlanetName = "Pământ"; ``` -Note, we could use a shorter name `planet`, but it might not be obvious what planet it refers to. It's nice to be more verbose. At least until the variable isNotTooLong. +Notează, am putea folosi un nume mai scurt decât `planet`, dar s-ar putea să nu fie evident la ce planetă se referă. E frumos să fim mai verbali. Cel puțin până când variabila nuEstePreaLungă. -## The name of the current visitor +## Numele vizitatorului curent ```js let currentUserName = "John"; ``` -Again, we could shorten that to `userName` if we know for sure that the user is current. +Din nou, am putea scurta acest `userName` dacă știm sigur că acest utilizator este unul curent. -Modern editors and autocomplete make long variable names easy to write. Don't save on them. A name with 3 words in it is fine. +Editoarele moderne și autocompletarea fac numele lungi de variabile ușor de scris. Nu economisi la ele. Un nume care conține trei cuvinte este în regulă. -And if your editor does not have proper autocompletion, get [a new one](/code-editors). +Și dacă editorul tău nu are autocompletare corectă, ia [unul nou](/code-editors). diff --git a/1-js/02-first-steps/04-variables/2-declare-variables/task.md b/1-js/02-first-steps/04-variables/2-declare-variables/task.md index f364badf4..4c718e5e9 100644 --- a/1-js/02-first-steps/04-variables/2-declare-variables/task.md +++ b/1-js/02-first-steps/04-variables/2-declare-variables/task.md @@ -2,7 +2,7 @@ importance: 3 --- -# Giving the right name +# Dând numele corect -1. Create a variable with the name of our planet. How would you name such a variable? -2. Create a variable to store the name of a current visitor to a website. How would you name that variable? +1. Crează o variabilă cu numele planetei noastre. Cum ai numi o astfel de variabilă? +2. Crează o variabilă care să stocheze numele unui vizitator curent al unui website. Cum ai numi o astfel de variabilă? diff --git a/1-js/02-first-steps/04-variables/3-uppercast-constant/solution.md b/1-js/02-first-steps/04-variables/3-uppercast-constant/solution.md index acd643fde..973a049ec 100644 --- a/1-js/02-first-steps/04-variables/3-uppercast-constant/solution.md +++ b/1-js/02-first-steps/04-variables/3-uppercast-constant/solution.md @@ -1,5 +1,5 @@ -We generally use upper case for constants that are "hard-coded". Or, in other words, when the value is known prior to execution and directly written into the code. +În general folosim majuscule pentru constante care sunt "hard-coded". Sau, în alte cuvinte, când valoarea este știută înainte de execuție și este scrisă direct în cod. -In this code, `birthday` is exactly like that. So we could use the upper case for it. +În acest cod, `birthday` este exact la fel. Deci am putea folosi majuscule pentru el. -In contrast, `age` is evaluated in run-time. Today we have one age, a year after we'll have another one. It is constant in a sense that it does not change through the code execution. But it is a bit "less of a constant" than `birthday`: it is calculated, so we should keep the lower case for it. +În contrast, `age` evaluat în timpul execuției. Astăzi avem o vârstă, peste un an vom avea alta. Este constantă în sensul că nu se schimbă pe parcursul execuției codului. Dar este un pic "mai puțin constantă" decât `birthday`: este calculată, deci ar trebui să păstrăm minuscule pentru aceasta. diff --git a/1-js/02-first-steps/04-variables/3-uppercast-constant/task.md b/1-js/02-first-steps/04-variables/3-uppercast-constant/task.md index 5fd18f90a..66281b555 100644 --- a/1-js/02-first-steps/04-variables/3-uppercast-constant/task.md +++ b/1-js/02-first-steps/04-variables/3-uppercast-constant/task.md @@ -2,9 +2,9 @@ importance: 4 --- -# Uppercase const? +# Const cu majuscule? -Examine the following code: +Examinează următorul cod: ```js const birthday = '18.04.1982'; @@ -12,13 +12,15 @@ const birthday = '18.04.1982'; const age = someCode(birthday); ``` -Here we have a constant `birthday` date and the `age` is calculated from `birthday` with the help of some code (it is not provided for shortness, and because details don't matter here). +Aici avem o constantă `birthday` pentru dată, și de asemenea constanta `age`. -Would it be right to use upper case for `birthday`? For `age`? Or even for both? +`age` este calculată din `birthday` folosind `someCode()`, ceea ce înseamnă un apel de funcție pe care nu l-am explicat încă (o vom face în curând!), dar detaliile nu contează aici, ideea este că `age` este calculată cumva pe baza `birthday`. + +Ar fi corect să folosim majuscule pentru `birthday`? Pentru `age`? Sau chiar pentru ambele? ```js -const BIRTHDAY = '18.04.1982'; // make uppercase? +const BIRTHDAY = '18.04.1982'; // facem BIRTHDAY cu majuscule? -const AGE = someCode(BIRTHDAY); // make uppercase? +const AGE = someCode(BIRTHDAY); // facem AGE cu majuscule? ``` diff --git a/1-js/02-first-steps/04-variables/article.md b/1-js/02-first-steps/04-variables/article.md index ec6c3a1c6..765886de6 100644 --- a/1-js/02-first-steps/04-variables/article.md +++ b/1-js/02-first-steps/04-variables/article.md @@ -1,274 +1,274 @@ -# Variables +# Variabile -Most of the time, a JavaScript application needs to work with information. Here are two examples: -1. An online shop -- the information might include goods being sold and a shopping cart. -2. A chat application -- the information might include users, messages, and much more. +În cea mai mare parte a timpului, o aplicație JavaScript are nevoie să lucreze cu informații. Aici sunt două example: +1. Un magazin online -- informația ar putea include bunurile vândute și un coș de cumpărături. +2. O aplicație de chat -- informația ar putea include utilizatori, mesaje, și mult mai multe. -Variables are used to store this information. +Variabilele sunt folosite pentru a stoca această informație. -## A variable +## O variabilă -A [variable](https://en.wikipedia.org/wiki/Variable_(computer_science)) is a "named storage" for data. We can use variables to store goodies, visitors, and other data. +O [variabilă](https://en.wikipedia.org/wiki/Variable_(computer_science)) este un "spațiu de stocare numit" pentru date. Putem folosi variabile pentru a stoca bunuri, vizitatori, și alte date. -To create a variable in JavaScript, use the `let` keyword. +Pentru a crea o variabilă în JavaScript, folosim cuvântul cheie `let` . -The statement below creates (in other words: *declares*) a variable with the name "message": +Declarația de mai jos crează (în alte cuvinte: *declară*) o variabilă cu numele "message": ```js let message; ``` -Now, we can put some data into it by using the assignment operator `=`: +Acum, putem pune niște date în aceasta folosind operatorul de alocare `=`: ```js let message; *!* -message = 'Hello'; // store the string 'Hello' in the variable named message +message = 'Bună'; // stochează șirul 'Hello' în variabila numită mesaj */!* ``` -The string is now saved into the memory area associated with the variable. We can access it using the variable name: +Șirul este acum salvat în zona de memorie asociată cu variabila. Putem să o accesăm folosind numele variabilei: ```js run let message; -message = 'Hello!'; +message = 'Bună!'; *!* -alert(message); // shows the variable content +alert(message); // arată conținutul variabilei */!* ``` -To be concise, we can combine the variable declaration and assignment into a single line: +Ca să fim conciși, putem să combinăm declarația variabilei și desemnarea ei într-o singură linie: ```js run -let message = 'Hello!'; // define the variable and assign the value +let message = 'Bună!'; // definește variabila și îi atribuie valoarea -alert(message); // Hello! +alert(message); // Bună! ``` -We can also declare multiple variables in one line: +De asemenea putem declara multiple variabile într-o singură linie: ```js no-beautify -let user = 'John', age = 25, message = 'Hello'; +let user = 'John', age = 25, message = 'Bună'; ``` -That might seem shorter, but we don't recommend it. For the sake of better readability, please use a single line per variable. +Asta ar putea să pară mai scurt, dar nu o recomandăm. De dragul unei lizibilități mai bune, te rugăm să folosești o singură linie per variabilă. -The multiline variant is a bit longer, but easier to read: +Varianta pe mai multe linii este puțin mai lungă, dar mai ușor de citit: ```js let user = 'John'; let age = 25; -let message = 'Hello'; +let message = 'Bună'; ``` -Some people also define multiple variables in this multiline style: +Unele persoane definesc de asemenea multiple variabile în acest stil multiliniar: ```js no-beautify let user = 'John', age = 25, - message = 'Hello'; + message = 'Bună'; ``` -...Or even in the "comma-first" style: +...Sau chiar în stilul "virgulă-înainte": ```js no-beautify let user = 'John' , age = 25 - , message = 'Hello'; + , message = 'Bună'; ``` -Technically, all these variants do the same thing. So, it's a matter of personal taste and aesthetics. +Technic, toate aceste variante fac același lucru. Deci, este o problemă de preferință personală și de estetică.. -````smart header="`var` instead of `let`" -In older scripts, you may also find another keyword: `var` instead of `let`: +````smart header="`var` în loc de `let`" +În scripturi mai vechi, ai putea găsi de asemenea un alt cuvânt cheie: `var` în loc de `let`: ```js -*!*var*/!* message = 'Hello'; +*!*var*/!* message = 'Bună'; ``` -The `var` keyword is *almost* the same as `let`. It also declares a variable, but in a slightly different, "old-school" way. +Termenul `var` este *aproape* la fel ca și `let`. El declară de asemenea o variabilă, dar într-un mod ușor diferit, de "școală-veche". -There are subtle differences between `let` and `var`, but they do not matter for us yet. We'll cover them in detail in the chapter . +Există diferențe subtile între `let` și `var`, dar nu contează pentru noi încă. O să le acoperim în detaliu în capitolul . ```` -## A real-life analogy +## O analogie din viața reală -We can easily grasp the concept of a "variable" if we imagine it as a "box" for data, with a uniquely-named sticker on it. +Putem înțelege ușor conceptul de "variabilă" dacă ne-o imaginăm drept o "cutie" pentru date, cu un abțibild cu nume unic pe ea. -For instance, the variable `message` can be imagined as a box labeled `"message"` with the value `"Hello!"` in it: +De exemplu, variabila `message` poate fi imaginată drept o cutie cu eticheta `"mesaj"` cu valoarea `"Bună!"` în ea: ![](variable.svg) -We can put any value in the box. +Putem pune orice valoare în cutie. -We can also change it as many times as we want: +De asemenea o putem schimba de câte ori vrem: ```js run let message; -message = 'Hello!'; +message = ''Bună!'; -message = 'World!'; // value changed +message = 'Lume!'; // valoare schimbată alert(message); ``` -When the value is changed, the old data is removed from the variable: +Când valoarea este schimbată, data veche este stearsă din variabilă: ![](variable-change.svg) -We can also declare two variables and copy data from one into the other. +De asemenea putem declara două variabile și copia datele din una în cealaltă.. ```js run -let hello = 'Hello world!'; +let hello = 'Bună lume!'; let message; *!* -// copy 'Hello world' from hello into message +// copiază 'Bună lume' din bună în message message = hello; */!* -// now two variables hold the same data -alert(hello); // Hello world! -alert(message); // Hello world! +// acum două variabile conțin aceleași date +alert(hello); // Bună lume!! +alert(message); // Bună lume! ``` -````warn header="Declaring twice triggers an error" -A variable should be declared only once. +````warn header="Declararea de două ori declanșează o eroare" +O variabilă ar trebui declarată o singură dată. -A repeated declaration of the same variable is an error: +O declarație repetată a aceleiași variabile este o eroare: ```js run -let message = "This"; +let message = "Acesta"; -// repeated 'let' leads to an error -let message = "That"; // SyntaxError: 'message' has already been declared +// 'let' repetat duce la o eroare +let message = "Acesta"; // SyntaxError: 'message' has already been declared ``` -So, we should declare a variable once and then refer to it without `let`. +Deci, ar trebui să declarăm o variabilă o dată și apoi să ne referim la aceasta fără `let`. ```` -```smart header="Functional languages" -It's interesting to note that there exist so-called [pure functional](https://en.wikipedia.org/wiki/Purely_functional_programming) programming languages, such as [Haskell](https://en.wikipedia.org/wiki/Haskell), that forbid changing variable values. +```smart header="Limbaje funcționale" +Este interesant de notat că există așa-numitele limbaje de programare [pur funcționale](https://en.wikipedia.org/wiki/Purely_functional_programming), cum ar fi [Haskell](https://en.wikipedia.org/wiki/Haskell), care interzic schimbarea valorii variabilelor. -In such languages, once the value is stored "in the box", it's there forever. If we need to store something else, the language forces us to create a new box (declare a new variable). We can't reuse the old one. +În limbaje ca acestea, odată ce valoarea este stocată "în cutie", există acolo pentru totdeauna. Dacă avem nevoie să stocăm altceva, limbajul ne forțează să creăm o nouă cutie (declarăm o nouă variabilă). Nu o putem refolosi pe cea veche. -Though it may seem a little odd at first sight, these languages are quite capable of serious development. More than that, there are areas like parallel computations where this limitation confers certain benefits. +Deși pare un pic ciudat la prima vedere, aceste limbaje sunt destul de capabile de dezvoltare serioasă. Mai mult decât atât, sunt zone ca de exemplu calcule paralele unde această limitare conferă beneficii sigure. ``` -## Variable naming [#variable-naming] +## Denumirea variabilelor [#variable-naming] -There are two limitations on variable names in JavaScript: +Există două limitări în denumirea variabilelor în JavaScript: -1. The name must contain only letters, digits, or the symbols `$` and `_`. -2. The first character must not be a digit. +1. Numele trebuie să conțină doar litere, numere, sau simboluri `$` și `_`. +2. Primul caracter nu trebuie să fie o cifră. -Examples of valid names: +Exemple de nume valide: ```js let userName; let test123; ``` -When the name contains multiple words, [camelCase](https://en.wikipedia.org/wiki/CamelCase) is commonly used. That is: words go one after another, each word except first starting with a capital letter: `myVeryLongName`. +Când numele conține cuvinte multiple, [camelCase](https://en.wikipedia.org/wiki/CamelCase) este adesea folosit. Adică: cuvintele vin unul după celălalt, fiecare cuvânt cu excepția celui dintâi începe cu majusculă: `numeleMeuFoarteLung`. -What's interesting -- the dollar sign `'$'` and the underscore `'_'` can also be used in names. They are regular symbols, just like letters, without any special meaning. +Ceea ce este interesant -- semnul de dolar `'$'` și bara jos `'_'` pot fi de asemenea folosite în nume. Acestea sunt simboluri obișnuite, la fel ca și literele, fără însemnătate specială. -These names are valid: +Aceste nume sunt valide: ```js run untrusted -let $ = 1; // declared a variable with the name "$" -let _ = 2; // and now a variable with the name "_" +let $ = 1; // a declarat o variabilă cu numele "$" +let _ = 2; // și acum o variabilă cu numele "_" alert($ + _); // 3 ``` -Examples of incorrect variable names: +Example de nume de variabile incorecte: ```js no-beautify -let 1a; // cannot start with a digit +let 1a; // nu poate începe cu o cifră -let my-name; // hyphens '-' aren't allowed in the name +let my-name; // liniuțele '-' nu sunt permise în nume ``` -```smart header="Case matters" -Variables named `apple` and `APPLE` are two different variables. +```smart header="Uscula contează" +Variabilele numite `apple` și `APPLE` sunt două variabile diferite. ``` -````smart header="Non-Latin letters are allowed, but not recommended" -It is possible to use any language, including cyrillic letters, Chinese logograms and so on, like this: +````smart header="Literele non-latine sunt permise, dar nu sunt recomandate" +Este posibil să folosim orice limbă, inclusiv litere chirilice, caractere chinezești și așa mai departe, precum acestea: ```js let имя = '...'; let 我 = '...'; ``` -Technically, there is no error here. Such names are allowed, but there is an international convention to use English in variable names. Even if we're writing a small script, it may have a long life ahead. People from other countries may need to read it some time. +Technic, aici nu este nicio eroare. Astfel de nume sunt permise, dar există o convenție internațională de a folosi limba engleză în denumirile variabilelor. Chiar dacă scriem un script mic, poate avea viață lungă. Oamenii din alte țări ar putea avea nevoie să le citescă uneori. ```` -````warn header="Reserved names" -There is a [list of reserved words](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Keywords), which cannot be used as variable names because they are used by the language itself. +````warn header="Nume rezervate" +Există o [listă de cuvinte rezervate](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Keywords), care nu poate fi folostă ca nume de variabile pentru că sunt folosite de către limbajul însuși. -For example: `let`, `class`, `return`, and `function` are reserved. +De exemplu: `let`, `class`, `return`, și `function` sunt rezervate.. -The code below gives a syntax error: +Codul următor dă eroare de sintaxă: ```js run no-beautify -let let = 5; // can't name a variable "let", error! -let return = 5; // also can't name it "return", error! +let let = 5; // nu putem numi o variabilă "let", eroare! +let return = 5; // de asemenea nu o putem numi "return", eroare! ``` ```` -````warn header="An assignment without `use strict`" +````warn header="O atribuire fără `use strict`" -Normally, we need to define a variable before using it. But in the old times, it was technically possible to create a variable by a mere assignment of the value without using `let`. This still works now if we don't put `use strict` in our scripts to maintain compatibility with old scripts. +În mod normal, avem nevoie să definim o variabilă înainte să o folosim. Dar în timpurile vechi, era technic posibil să creezi o variabilă prin simpla alocare a unei valori fără a folosi `let`. Acesta încă funcționează acum dacă nu punem `use strict` în scriptul nostru pentru a menține compatibilitatea cu scripturile vechi. ```js run no-strict -// note: no "use strict" in this example +// notă: fără "use strict" în acest exemplu -num = 5; // the variable "num" is created if it didn't exist +num = 5; // variabila "num" este creată chiar dacă nu există alert(num); // 5 ``` -This is a bad practice and would cause an error in strict mode: +Aceasta este o practică greșită și ar putea produce o eroare în modul strict: ```js "use strict"; *!* -num = 5; // error: num is not defined +num = 5; // eroare: num nu este definit */!* ``` ```` -## Constants +## Constante -To declare a constant (unchanging) variable, use `const` instead of `let`: +Pentru a declara o constantă (care nu se schimbă) variabilă, folosim `const` în loc de `let`: ```js const myBirthday = '18.04.1982'; ``` -Variables declared using `const` are called "constants". They cannot be reassigned. An attempt to do so would cause an error: +Variabilele declarate folosind `const` se numesc "constante". Ele nu pot fi realocate. O încercare de a face acest lucru va produce o eroare: ```js run const myBirthday = '18.04.1982'; -myBirthday = '01.01.2001'; // error, can't reassign the constant! +myBirthday = '01.01.2001'; // eroare, nu putem realoca constanta! ``` -When a programmer is sure that a variable will never change, they can declare it with `const` to guarantee and clearly communicate that fact to everyone. +Când un programator este sigur că acea variabilă nu se va schimba niciodată, o poate declara folosind `const` pentru a garanta și a comunica clar acest fapt tuturor. -### Uppercase constants +### Constante cu majuscule -There is a widespread practice to use constants as aliases for difficult-to-remember values that are known prior to execution. +Este o practica răspândită de a folosi constante drept așa-zise valori greu de reținut care sunt cunoscute înainte de execuție. -Such constants are named using capital letters and underscores. +Aceste constante sunt denumite folosind majuscule și bară jos. -For instance, let's make constants for colors in so-called "web" (hexadecimal) format: +De exemplu, să facem o constantă pentru culori în așa-numitul "web" (hexadecimal) format: ```js run const COLOR_RED = "#F00"; @@ -276,70 +276,70 @@ const COLOR_GREEN = "#0F0"; const COLOR_BLUE = "#00F"; const COLOR_ORANGE = "#FF7F00"; -// ...when we need to pick a color +// ...când avem nevoie să alegem o culoare let color = COLOR_ORANGE; alert(color); // #FF7F00 ``` -Benefits: +Beneficii: -- `COLOR_ORANGE` is much easier to remember than `"#FF7F00"`. -- It is much easier to mistype `"#FF7F00"` than `COLOR_ORANGE`. -- When reading the code, `COLOR_ORANGE` is much more meaningful than `#FF7F00`. +- `COLOR_ORANGE` este mai ușor de reținut decât `"#FF7F00"`. +- Este mult mai ușor de scris greșit `"#FF7F00"` decât `COLOR_ORANGE`. +- Când citim codul, `COLOR_ORANGE` are o însemnătate mai mare decât `#FF7F00`. -When should we use capitals for a constant and when should we name it normally? Let's make that clear. +Când ar trebui să folosim majuscule pentru o constantă și când ar trebui să o denumim în mod obișnuit? Haideți să clarificăm asta. -Being a "constant" just means that a variable's value never changes. But there are constants that are known prior to execution (like a hexadecimal value for red) and there are constants that are *calculated* in run-time, during the execution, but do not change after their initial assignment. +A fi o "constantă" înseamnă doar a fi o valoare a unei variabile care nu se schimbă. Dar există și constante care sunt cunoscute înainte de execuție (ca de exemplu valoarea hexadecimală pentru roșu) și există constante care sunt *calculate* în timpul execuției, dar nu se schimbă după ce sunt alocate inițial. -For instance: +De exemplu: ```js -const pageLoadTime = /* time taken by a webpage to load */; +const pageLoadTime = /* durata timpului de încărcare a unei pagini web */; ``` -The value of `pageLoadTime` is not known prior to the page load, so it's named normally. But it's still a constant because it doesn't change after assignment. +Valoarea lui `pageLoadTime` nu este cunoscută înainte ca pagina să se încarce, astfel că este denumită obișnuit. Dar este totuși o constantă pentru că nu se schimbă după ce este alocată. -In other words, capital-named constants are only used as aliases for "hard-coded" values. +În alte cuvinte, constantele cu majuscule sunt folosite doar ca așa-zise valori "hard-coded". -## Name things right +## Denumirea corectă a lucrurilor -Talking about variables, there's one more extremely important thing. +Vorbind despre variabile, mai este un lucru extrem de important. -A variable name should have a clean, obvious meaning, describing the data that it stores. +Numele unei variabile trebuie să aibă o semnificație clară, evidentă, care să descrie datele pe care le stochează. -Variable naming is one of the most important and complex skills in programming. A quick glance at variable names can reveal which code was written by a beginner versus an experienced developer. +Numirea variabilelor este una dintre cele mai importante și mai complexe abilități în programare. O privire rapidă asupra numelor variabilelor poate dezvălui ce cod a fost scris de un începător față de un programator experimentat. -In a real project, most of the time is spent modifying and extending an existing code base rather than writing something completely separate from scratch. When we return to some code after doing something else for a while, it's much easier to find information that is well-labeled. Or, in other words, when the variables have good names. +Într-un proiect real, cea mai mare parte a timpului se petrece modificând și extinzând o bază de cod existentă, mai degrabă decât scriind ceva complet separat de la zero. Atunci când ne întoarcem la un cod după ce am făcut altceva pentru o vreme, este mult mai ușor să găsim informații care sunt bine etichetate. Sau, cu alte cuvinte, când variabilele au nume bune. -Please spend time thinking about the right name for a variable before declaring it. Doing so will repay you handsomely. +Te rog petrece timp gândindu-te la denumirea corectă pentru o variabilă înainte să o declari. Făcând acest lucru te răsplătești frumos. -Some good-to-follow rules are: +Câteva reguli bune de urmat sunt: -- Use human-readable names like `userName` or `shoppingCart`. -- Stay away from abbreviations or short names like `a`, `b`, `c`, unless you really know what you're doing. -- Make names maximally descriptive and concise. Examples of bad names are `data` and `value`. Such names say nothing. It's only okay to use them if the context of the code makes it exceptionally obvious which data or value the variable is referencing. -- Agree on terms within your team and in your own mind. If a site visitor is called a "user" then we should name related variables `currentUser` or `newUser` instead of `currentVisitor` or `newManInTown`. +- Folosește nume uman-reproductibile ca `userName` sau `shoppingCart`. +- Stai departe de abrevieri sau nume scurte ca `a`, `b`, `c`, decât dacă știi cu adevărat ceea ce faci. +- Fă Fă ca numele să fie cât mai descriptiv și concis. Exemple de nume proaste sunt `data` și `value`. Astfel de nume nu spun nimic. Este în regulă să le folosiți doar dacă contextul codului face extrem de evident la ce date sau valoare face referire variabila. +- Pune-te de acord cu echipa și ține minte. Dacă vizitatorul unui site este denumit ca "user" atunci ar trebui ca numele variabilelor legate să fie `currentUser` sau `newUser` în loc de `currentVisitor` sau `newManInTown`. -Sounds simple? Indeed it is, but creating descriptive and concise variable names in practice is not. Go for it. +Sună simplu? Chiar este, dar crearea de variabile descriptive și concise în practică nu este. Încearcă. -```smart header="Reuse or create?" -And the last note. There are some lazy programmers who, instead of declaring new variables, tend to reuse existing ones. +```smart header="Reutilizare sau creare?" +Și ultima notă. Există programatori leneși care, în loc să declare variabile noi, tind să le reutilizeze pe cele deja existente. -As a result, their variables are like boxes into which people throw different things without changing their stickers. What's inside the box now? Who knows? We need to come closer and check. +Drept rezultat, variabilele lor sunt ca niște cutii în care oamenii aruncă diferite lucruri fără să schimbe etichetele. Ce este înăuntrul cutiei acum? Cine știe? Trebuie să ne apropiem și să verificăm. -Such programmers save a little bit on variable declaration but lose ten times more on debugging. +Astfel de programatori salvează puțin din declararea variabilelor dar pierd de zece ori mai mult să remedieze erorile. -An extra variable is good, not evil. +O variabilă extra este bună, nu rea. -Modern JavaScript minifiers and browsers optimize code well enough, so it won't create performance issues. Using different variables for different values can even help the engine optimize your code. +Minificatoarele și browserele moderne de JavaScript optimizează codul suficient de bine, astfel încât să nu creeze probleme de performanță. Folosirea unor variabile diferite pentru valori diferite poate chiar ajuta motorul să vă optimizeze codul. ``` -## Summary +## Sumar -We can declare variables to store data by using the `var`, `let`, or `const` keywords. +Putem declara variabile pentru a stoca date folosind `var`, `let`, sau cuvântul cheie `const`. -- `let` -- is a modern variable declaration. -- `var` -- is an old-school variable declaration. Normally we don't use it at all, but we'll cover subtle differences from `let` in the chapter , just in case you need them. -- `const` -- is like `let`, but the value of the variable can't be changed. +- `let` -- este o declarație modernă de variabilă. +- `var` -- este o declarație de variabilă de "școală-veche". În mod normal nu o mai folosim deloc, dar o să acoperim diferențele subtile față de `let` în capitolul , doar în cazul în care ai nevoie de ele. +- `const` -- este la fel ca `let`, doar că valoarea variabilei nu se poate schimba. -Variables should be named in a way that allows us to easily understand what's inside them. +Variabilele ar trebui să fie denumite într-un mod care să ne permită să înțelegem cu ușurință ce se află în ele. diff --git a/1-js/02-first-steps/04-variables/variable-change.svg b/1-js/02-first-steps/04-variables/variable-change.svg index 1b2679238..ed9d1062e 100644 --- a/1-js/02-first-steps/04-variables/variable-change.svg +++ b/1-js/02-first-steps/04-variables/variable-change.svg @@ -1 +1 @@ -"World!""Hello!"message \ No newline at end of file +"Lume!""Bună!"message diff --git a/1-js/02-first-steps/04-variables/variable.svg b/1-js/02-first-steps/04-variables/variable.svg index 1c3d8b0cb..5dcfaf8c4 100644 --- a/1-js/02-first-steps/04-variables/variable.svg +++ b/1-js/02-first-steps/04-variables/variable.svg @@ -1 +1 @@ -"Hello!"message \ No newline at end of file +"Bună!"message \ No newline at end of file