Skip to content

Commit 39d00b2

Browse files
authored
Update article.md
Up to Summary
1 parent bcccb21 commit 39d00b2

File tree

1 file changed

+43
-41
lines changed

1 file changed

+43
-41
lines changed

1-js/02-first-steps/07-type-conversions/article.md

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,121 +1,123 @@
1-
# Type Conversions
1+
# Conversii de tip
22

3-
Most of the time, operators and functions automatically convert the values given to them to the right type.
3+
Majoritatea timpului, operatorii si funcțiile convertesc automat valorile date catre tipul corect.
44

5-
For example, `alert` automatically converts any value to a string to show it. Mathematical operations convert values to numbers.
5+
De exemplu, `alert` convertește automat orice valoare catre un șir pentru a o arăta. Operațiile matematice convertesc valorile catre numere.
66

7-
There are also cases when we need to explicitly convert a value to the expected type.
7+
Există și cazuri unde este nevoie sa convertim explicit o valoare către tipul așteptat.
88

99
```smart header="Not talking about objects yet"
10-
In this chapter, we won't cover objects. For now we'll just be talking about primitives.
10+
În acest captiol, nu vom acoperi obiectele. Pentru moment vom vorbi doar despre primitive.
1111
12-
Later, after we learn about objects, in the chapter <info:object-toprimitive> we'll see how objects fit in.
12+
Mai târziu, dupa ce vom învăța despre obiecte, în acest capitol <info:object-toprimitive> vom vedea cum se incadrează obiectele.
1313
```
1414

15-
## String Conversion
15+
## Conversia unui Șir
1616

17-
String conversion happens when we need the string form of a value.
17+
Conversia unui șir se întâmplă când avem nevoie de forma de șir a unei valori.
1818

19-
For example, `alert(value)` does it to show the value.
19+
De exemplu, `alert(value)` o face pentru a arăta valoarea.
2020

21-
We can also call the `String(value)` function to convert a value to a string:
21+
Totodată, putem apela funcța `String(value)` pentru a converti o valoare către un șir
2222

2323
```js run
2424
let value = true;
2525
alert(typeof value); // boolean
2626

2727
*!*
28-
value = String(value); // now value is a string "true"
29-
alert(typeof value); // string
28+
value = String(value); // acum valoarea este un "adevărat" șir
29+
alert(typeof value); // șir
3030
*/!*
3131
```
3232

33-
String conversion is mostly obvious. A `false` becomes `"false"`, `null` becomes `"null"`, etc.
33+
Conversia unui șir este destul de evidentă. Un `false` devine `"false"`, `null` devine `"null"`, etc.
3434

35-
## Numeric Conversion
35+
## Conversia Numerică
3636

37-
Numeric conversion happens in mathematical functions and expressions automatically.
37+
Conversia numerică se petrece in funcții și expresii matematice automat.
3838

39-
For example, when division `/` is applied to non-numbers:
39+
De exemplu, când împărțirea `/` este aplicată non-numerelor:
4040

4141
```js run
42-
alert( "6" / "2" ); // 3, strings are converted to numbers
42+
alert( "6" / "2" ); // 3, șirurile sunt convertite către numere
4343
```
4444

45-
We can use the `Number(value)` function to explicitly convert a `value` to a number:
45+
Putem folosi funcția `Number(value)` pentru a converti explicit o `value` către un număr.
4646

4747
```js run
4848
let str = "123";
49-
alert(typeof str); // string
49+
alert(typeof str); // șir
5050

51-
let num = Number(str); // becomes a number 123
51+
let num = Number(str); // devine un număr 123
5252

53-
alert(typeof num); // number
53+
alert(typeof num); // număr
5454
```
5555

56-
Explicit conversion is usually required when we read a value from a string-based source like a text form but expect a number to be entered.
56+
Conversia explicită de obicei este cerută când citim o valoarea dintr-o sursă bazată pe un șir ca și un formular text dar așteaptă un număr să fie inclus.
5757

58-
If the string is not a valid number, the result of such a conversion is `NaN`. For instance:
58+
Dacă șirul nu este un număr valid, rezultatul acestei conversii este `NaN`. De exemplu:
5959

6060
```js run
61-
let age = Number("an arbitrary string instead of a number");
61+
let age = Number("un șir arbitrar in locul unui număr");
6262

63-
alert(age); // NaN, conversion failed
63+
alert(age); // NaN, conversie eșuată
6464
```
6565

66-
Numeric conversion rules:
66+
Regulile conversiei numerice:
6767

68-
| Value | Becomes... |
68+
| Valoare | Devine... |
6969
|-------|-------------|
7070
|`undefined`|`NaN`|
7171
|`null`|`0`|
7272
|<code>true&nbsp;and&nbsp;false</code> | `1` and `0` |
73-
| `string` | Whitespaces from the start and end are removed. If the remaining string is empty, the result is `0`. Otherwise, the number is "read" from the string. An error gives `NaN`. |
73+
| `string` | Spațiile goale de la ïnceput și sfârșit sunt eliminate. Daca șirul rămas este gol, rezultatul este `0`. Altfel numărul este "citit" din șir . O eroare transmite `NaN`. |
7474

75-
Examples:
75+
Exemple:
7676

7777
```js run
7878
alert( Number(" 123 ") ); // 123
79-
alert( Number("123z") ); // NaN (error reading a number at "z")
79+
alert( Number("123z") ); // NaN (eroare la citirea unui numar la "z")
8080
alert( Number(true) ); // 1
8181
alert( Number(false) ); // 0
8282
```
8383

84-
Please note that `null` and `undefined` behave differently here: `null` becomes zero while `undefined` becomes `NaN`.
84+
Va rugăm sa notați faptul că `null` și `undefined` se comportă diferit aici: `null` devine 0, în timp ce `undefined` devine `NaN`.
8585

86-
Most mathematical operators also perform such conversion, we'll see that in the next chapter.
86+
Cei mai mulți operatori matematici execută o astfel de conversie, vom vedea aceasta in capitolul următor.
8787

8888
## Boolean Conversion
89+
## Conversia Boolean
8990

90-
Boolean conversion is the simplest one.
91+
Conversia boolean este cea mai simplă.
9192

92-
It happens in logical operations (later we'll meet condition tests and other similar things) but can also be performed explicitly with a call to `Boolean(value)`.
93+
Are loc in operațiile logice (mai tarziu vom cunoaște teste condiționale si alte lucruri similare) dar poate fi executată specific cu o apelare la `Boolean(value)`.
9394

94-
The conversion rule:
95+
Regula conversiei:
9596

96-
- Values that are intuitively "empty", like `0`, an empty string, `null`, `undefined`, and `NaN`, become `false`.
97-
- Other values become `true`.
97+
- Valorile care sunt "goale" intuitiv, ca și `0`, un șir gol, `null`, `undefined`, and `NaN`, devin `false`.
98+
- Alte valori devin `true`.
9899

99-
For instance:
100+
De exemplu:
100101

101102
```js run
102103
alert( Boolean(1) ); // true
103104
alert( Boolean(0) ); // false
104105

105-
alert( Boolean("hello") ); // true
106+
alert( Boolean("salut") ); // true
106107
alert( Boolean("") ); // false
107108
```
108109

109110
````warn header="Please note: the string with zero `\"0\"` is `true`"
110-
Some languages (namely PHP) treat `"0"` as `false`. But in JavaScript, a non-empty string is always `true`.
111+
Alte limbaje (anume PHP) trateaza `"0"` ca și `false`. Dar in JavaScript, un șir ne-gol este întotdeauna `true`.
111112

112113
```js run
113114
alert( Boolean("0") ); // true
114-
alert( Boolean(" ") ); // spaces, also true (any non-empty string is true)
115+
alert( Boolean(" ") ); // spații, de asemenea true (orice șir ne-gol este true)
115116
```
116117
````
117118
118119
## Summary
120+
## Rezumat
119121
120122
The three most widely used type conversions are to string, to number, and to boolean.
121123

0 commit comments

Comments
 (0)