Skip to content

Commit 9810824

Browse files
Merge pull request #49 from hadamariaa/feature/code-structure-ok
translated code structure
2 parents 0831cfc + 8999512 commit 9810824

File tree

1 file changed

+45
-40
lines changed

1 file changed

+45
-40
lines changed
Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,60 @@
1-
# Code structure
1+
# Structura codului
22

3-
The first thing we'll study is the building blocks of code.
3+
Primele lucruri pe care le vom studia sunt blocurile de bază ale codului.
44

5-
## Statements
5+
## Declarații
66

7-
Statements are syntax constructs and commands that perform actions.
7+
Declarațiile sunt construcții de sintaxă și comenzi care efectuează acțiuni.
88

9-
We've already seen a statement, `alert('Hello, world!')`, which shows the message "Hello, world!".
9+
Deja am întâlnit o declarație, `alert('Hello, world!')`, care afișează mesajul "Hello, world!".
1010

11-
We can have as many statements in our code as we want. Statements can be separated with a semicolon.
11+
Putem avea cât de multe declarații vrem în codul nostru. Declarațiile pot fi separate prin punct și virgulă.
1212

13-
For example, here we split "Hello World" into two alerts:
13+
De exemplu, aici vom despărți "Hello World" în două alerte diferite:
1414

1515
```js run no-beautify
1616
alert('Hello'); alert('World');
1717
```
1818

19-
Usually, statements are written on separate lines to make the code more readable:
19+
De obicei, declarațiile sunt scrise pe linii separate pentru a face codul mai lizibil:
2020

2121
```js run no-beautify
2222
alert('Hello');
2323
alert('World');
2424
```
2525

26-
## Semicolons [#semicolon]
26+
## Punctul și virgula [#semicolon]
2727

28-
A semicolon may be omitted in most cases when a line break exists.
28+
Punctul și virgula pot fi omise în majoritatea cazurilor când există o pauză de linie.
2929

30-
This would also work:
30+
Acest lucru ar funcționa, de asemenea:
3131

3232
```js run no-beautify
3333
alert('Hello')
3434
alert('World')
3535
```
3636

37-
Here, JavaScript interprets the line break as an "implicit" semicolon. This is called an [automatic semicolon insertion](https://tc39.github.io/ecma262/#sec-automatic-semicolon-insertion).
37+
Aici, JavaScript interpretează întreruperea liniei ca punct și virgulă „implicit”. Aceasta se numește [introducerea automata a punctului și virgulei](https://tc39.github.io/ecma262/#sec-automatic-semicolon-insertion).
3838

39-
**In most cases, a newline implies a semicolon. But "in most cases" does not mean "always"!**
39+
**În cele mai multe cazuri, o linie nouă implică punct și virgulă. Dar „în majoritatea cazurilor” nu înseamnă „întotdeauna!**
4040

41-
There are cases when a newline does not mean a semicolon. For example:
41+
Sunt cazuri când o linie nouă nu înseamna un punct și virgulă. De exemplu:
4242

4343
```js run no-beautify
4444
alert(3 +
4545
1
4646
+ 2);
4747
```
4848

49+
4950
The code outputs `6` because JavaScript does not insert semicolons here. It is intuitively obvious that if the line ends with a plus `"+"`, then it is an "incomplete expression", so a semicolon there would be incorrect. And in this case, that works as intended.
5051

51-
**But there are situations where JavaScript "fails" to assume a semicolon where it is really needed.**
52+
**Există situații în care JavaScript „eșuează” să-și asume un punct și virgulă unde este cu adevărat necesar.**
5253

53-
Errors which occur in such cases are quite hard to find and fix.
54+
Erorile care apar în astfel de cazuri sunt destul de greu de găsit și de remediat.
5455

55-
````smart header="An example of an error"
56-
If you're curious to see a concrete example of such an error, check this code out:
56+
````smart header="Exemplu de eroare"
57+
Dacă sunteți curios să vedeți un exemplu concret de astfel de eroare, verificați acest cod:
5758
5859
```js run
5960
alert("Hello");
@@ -86,70 +87,74 @@ alert("Hello")[1, 2].forEach(alert);
8687
Looks weird, right? Such merging in this case is just wrong. We need to put a semicolon after `alert` for the code to work correctly.
8788
8889
This can happen in other situations also.
90+
8991
````
9092

91-
We recommend putting semicolons between statements even if they are separated by newlines. This rule is widely adopted by the community. Let's note once again -- *it is possible* to leave out semicolons most of the time. But it's safer -- especially for a beginner -- to use them.
93+
Vă recomandăm să puneți punct și virgulă între instrucțiuni, chiar dacă sunt separate prin linii noi. Această regulă este adoptată pe scară largă de comunitate. Să notăm încă o dată -- *este posibil* să omitem punctul și virgula de cele mai multe ori. Dar este mai sigur -- mai ales pentru un începător -- să o folosească.
94+
9295

9396
## Comments [#code-comments]
9497

95-
As time goes on, programs become more and more complex. It becomes necessary to add *comments* which describe what the code does and why.
9698

97-
Comments can be put into any place of a script. They don't affect its execution because the engine simply ignores them.
99+
Pe măsură ce timpul trece, programele devin din ce în ce mai complexe. Devine necesar să adăugați *comentarii* care descriu ce face codul și de ce.
98100

99-
**One-line comments start with two forward slash characters `//`.**
101+
Comentariile pot fi puse în orice loc al unui script. Acestea nu afectează execuția acestuia, deoarece motorul pur și simplu le ignoră.
100102

101-
The rest of the line is a comment. It may occupy a full line of its own or follow a statement.
103+
**Comentariile pe o singură linie încep cu două caractere de slash înainte `//`.**
102104

103-
Like here:
105+
Restul liniei este un comentariu. Poate ocupa o linie completă proprie sau poate urma o declarație.
106+
107+
Ca aici:
104108
```js run
105-
// This comment occupies a line of its own
109+
// Acest comentariu ocupă o linie proprie
106110
alert('Hello');
107111

108-
alert('World'); // This comment follows the statement
112+
alert('World'); // Acest comentariu urmează afirmația
109113
```
110114

111-
**Multiline comments start with a forward slash and an asterisk <code>/&#42;</code> and end with an asterisk and a forward slash <code>&#42;/</code>.**
115+
**Comentariile pe mai multe linii încep cu un slash înainte și un asterisc <code>/&#42;</code> și se încheie cu un asterisc și cu un slash înainte <code>&#42;/</code>.**
112116

113-
Like this:
117+
În felul următor:
114118

115119
```js run
116-
/* An example with two messages.
117-
This is a multiline comment.
120+
/* Un exemplu cu două mesaje.
121+
Acesta este un comentariu pe mai multe linii.
118122
*/
119123
alert('Hello');
120124
alert('World');
121125
```
122126

123-
The content of comments is ignored, so if we put code inside <code>/&#42; ... &#42;/</code>, it won't execute.
127+
Conținutul comentariilor este ignorat, deci dacă punem cod în interior <code>/&#42; ... &#42;/</code>, acesta nu o să se execute.
124128

125-
Sometimes it can be handy to temporarily disable a part of code:
129+
Uneori, poate fi util să dezactivați temporar o parte a codului:
126130

127131
```js run
128-
/* Commenting out the code
132+
/* Comentând codul
129133
alert('Hello');
130134
*/
131135
alert('World');
132136
```
133137

138+
134139
```smart header="Use hotkeys!"
135140
In most editors, a line of code can be commented out by pressing the `key:Ctrl+/` hotkey for a single-line comment and something like `key:Ctrl+Shift+/` -- for multiline comments (select a piece of code and press the hotkey). For Mac, try `key:Cmd` instead of `key:Ctrl` and `key:Option` instead of `key:Shift`.
136141
```
137142

138-
````warn header="Nested comments are not supported!"
139-
There may not be `/*...*/` inside another `/*...*/`.
143+
````warn header="Comentariile imbricate nu sunt suportate!"
144+
Nu poate exista `/*...*/` în interiorul altui `/*...*/`.
140145
141-
Such code will die with an error:
146+
Acest cod va genera o eroare:
142147
143148
```js run no-beautify
144149
/*
145-
/* nested comment ?!? */
150+
/* comentariu imbricat ?!? */
146151
*/
147152
alert( 'World' );
148153
```
149154
````
150155

151-
Please, don't hesitate to comment your code.
156+
Vă rugăm, nu ezitați să vă comentați codul.
152157

153-
Comments increase the overall code footprint, but that's not a problem at all. There are many tools which minify code before publishing to a production server. They remove comments, so they don't appear in the working scripts. Therefore, comments do not have negative effects on production at all.
158+
Comentariile cresc amprenta generală a codului, dar aceasta nu este deloc o problemă. Există multe instrumente care reduc codul înainte de publicarea pe un server de producție. Șterg comentariile, deci nu apar în scripturile de lucru. Prin urmare comentariile nu au deloc efecte negative asupra producției.
154159

155-
Later in the tutorial there will be a chapter <info:code-quality> that also explains how to write better comments.
160+
Mai târziu în tutorial va exista un capitol <info:code-quality> care explică, de asemenea, cum să scrieți comentarii mai bune.

0 commit comments

Comments
 (0)