|
1 | | -# Data types |
| 1 | +# Duomenų tipai |
2 | 2 |
|
3 | | -A variable in JavaScript can contain any data. A variable can at one moment be a string and at another be a number: |
| 3 | +Kintamasis JavaScript gali savyje laikyti bet kokius duomenis. Kintamasis gali vienu momentu būti eilutė, o kitu numeris: |
4 | 4 |
|
5 | 5 | ```js |
6 | 6 | // no error |
7 | | -let message = "hello"; |
| 7 | +let message = "labas"; |
8 | 8 | message = 123456; |
9 | 9 | ``` |
10 | 10 |
|
11 | | -Programming languages that allow such things are called "dynamically typed", meaning that there are data types, but variables are not bound to any of them. |
| 11 | +Programinės kalbos, kurios tai leidžia yra vadinamos "dinamiškai tipizuotomis" (ang. "dynamically typed"), tai reiškia, kad duomenų tipai yra, tačiau kintamieji nėra prie jų pririšti. |
12 | 12 |
|
13 | | -There are seven basic data types in JavaScript. Here, we'll cover them in general and in the next chapters we'll talk about each of them in detail. |
| 13 | +JavaScript turi septynis pagrindinius duomenų tipus. Čia mes juos peržvelgsime bendrai, o tolesniuose skyriuose apie kiekvieną pakalbėsime detaliau. |
14 | 14 |
|
15 | | -## A number |
| 15 | +## Skaičius |
16 | 16 |
|
17 | 17 | ```js |
18 | 18 | let n = 123; |
19 | 19 | n = 12.345; |
20 | 20 | ``` |
21 | 21 |
|
22 | | -The *number* type represents both integer and floating point numbers. |
| 22 | +*Skaičiaus* tipas atstovauja sveikus skaičius (ang. integer) ir slankiojo kablelio skaičius (ang. floating point numbers). |
23 | 23 |
|
24 | | -There are many operations for numbers, e.g. multiplication `*`, division `/`, addition `+`, subtraction `-`, and so on. |
| 24 | +Netrūksta veiksmų skaičiams, kaip pavyzdžiui daugyba `*`, dalyba `/`, sudėtis `+`, atimtis `-`, ir taip toliau. |
25 | 25 |
|
26 | | -Besides regular numbers, there are so-called "special numeric values" which also belong to this data type: `Infinity`, `-Infinity` and `NaN`. |
| 26 | +Kartu su įprastiniais skaičiais, yra taip vadinamos "specialios skaitinės reikšmės", kurios taip pat priklauso šiam duomenų tipui: `Infinity`, `-Infinity` ir `NaN`. |
27 | 27 |
|
28 | | -- `Infinity` represents the mathematical [Infinity](https://en.wikipedia.org/wiki/Infinity) ∞. It is a special value that's greater than any number. |
| 28 | +- `Infinity` atstovauja matematinę [Begalybę](https://en.wikipedia.org/wiki/Infinity) ∞. Tai speciali reikšmė, kuri yra didesnė nei bet koks skaičius. |
29 | 29 |
|
30 | | - We can get it as a result of division by zero: |
| 30 | + Ją gauname kaip rezultatą kai daliname iš nulio: |
31 | 31 |
|
32 | 32 | ```js run |
33 | 33 | alert( 1 / 0 ); // Infinity |
34 | 34 | ``` |
35 | 35 |
|
36 | | - Or just reference it directly: |
| 36 | + Arba kai tiesiogiai nurodome: |
37 | 37 |
|
38 | 38 | ```js run |
39 | 39 | alert( Infinity ); // Infinity |
40 | 40 | ``` |
41 | | -- `NaN` represents a computational error. It is a result of an incorrect or an undefined mathematical operation, for instance: |
| 41 | +- `NaN` atstovauja skaičiavimo klaidą. Tai yra neteisingo ar neapibrėžto (ang. undefined) mateminio veiksmo rezultatas, pavyzdžiui: |
42 | 42 |
|
43 | 43 | ```js run |
44 | | - alert( "not a number" / 2 ); // NaN, such division is erroneous |
| 44 | + alert( "ne skaičius" / 2 ); // NaN, tokia dalyba yra klaidinga |
45 | 45 | ``` |
46 | 46 |
|
47 | | - `NaN` is sticky. Any further operation on `NaN` returns `NaN`: |
| 47 | + `NaN` yra kabus. Bet kokie tolesni veiksmai su `NaN` grąžins `NaN`: |
48 | 48 |
|
49 | 49 | ```js run |
50 | | - alert( "not a number" / 2 + 5 ); // NaN |
| 50 | + alert( "ne skaičius" / 2 + 5 ); // NaN |
51 | 51 | ``` |
52 | 52 |
|
53 | | - So, if there's a `NaN` somewhere in a mathematical expression, it propagates to the whole result. |
| 53 | + Taigi, jeigu kažkur matematinėje formulėje yra `NaN` jis persiduoda į visus tolesnius rezultatus. |
54 | 54 |
|
55 | | -```smart header="Mathematical operations are safe" |
56 | | -Doing maths is "safe" in JavaScript. We can do anything: divide by zero, treat non-numeric strings as numbers, etc. |
| 55 | +```smart header="Matematiniai veiksmai yra saugūs" |
| 56 | +Užsiimti matematika JavaScript yra "saugu". Galime daryti viską: dalinti iš nulio, elgtis su neskaitinėmis eilutėmis kaip su skaičiais ir t.t. |
57 | 57 |
|
58 | | -The script will never stop with a fatal error ("die"). At worst, we'll get `NaN` as the result. |
| 58 | +Skriptas niekada nesustos dėl lemtingos klaidos ("mirs"). Blogiausia kas gali būti, mes gausime `NaN` kaip rezultatą. |
59 | 59 | ``` |
60 | 60 |
|
61 | | -Special numeric values formally belong to the "number" type. Of course they are not numbers in the common sense of this word. |
| 61 | +Specialios skaitinės reikšmės priklauso "skaičių" tipui. Žinoma, jie nėra skaičiai įprastine šio žodžio reikšme. |
62 | 62 |
|
63 | | -We'll see more about working with numbers in the chapter <info:number>. |
| 63 | +Daugiau apie darbą su skaičiais bus skyriuje <info:number>. |
64 | 64 |
|
65 | | -## A string |
| 65 | +## Eilutė |
66 | 66 |
|
67 | | -A string in JavaScript must be surrounded by quotes. |
| 67 | +Eilutė JavaScript turi būti apsupta kabutėmis. |
68 | 68 |
|
69 | 69 | ```js |
70 | | -let str = "Hello"; |
71 | | -let str2 = 'Single quotes are ok too'; |
72 | | -let phrase = `can embed ${str}`; |
| 70 | +let str = "Labas"; |
| 71 | +let str2 = 'Viengubos kabutės taip pat tinka'; |
| 72 | +let phrase = `galima įterpti ${str}`; |
73 | 73 | ``` |
74 | 74 |
|
75 | | -In JavaScript, there are 3 types of quotes. |
| 75 | +JavaScript turi 3-ų tipų kabutes. |
76 | 76 |
|
77 | | -1. Double quotes: `"Hello"`. |
78 | | -2. Single quotes: `'Hello'`. |
79 | | -3. Backticks: <code>`Hello`</code>. |
| 77 | +1. Dvigubos kabutės: `"Hello"`. |
| 78 | +2. Viengubos kabutės: `'Hello'`. |
| 79 | +3. Atvirkštinės kabutės: <code>`Labas`</code>. |
80 | 80 |
|
81 | | -Double and single quotes are "simple" quotes. There's no difference between them in JavaScript. |
| 81 | +Dvigubos ir viengubos kabutės yra "paprastosios" kabutės. Tarp jų nėra jokio skirtumo JavaScript. |
82 | 82 |
|
83 | | -Backticks are "extended functionality" quotes. They allow us to embed variables and expressions into a string by wrapping them in `${…}`, for example: |
| 83 | +Atvirkštinės kabutės yra kabutės su "išplėstu funkcionalumu". Jos leidžia mums įterpti kintamuosius ir išraiškas į pačią eilutę kai apsupame juos tokiais ženklais `${…}`, pavyzdžiui: |
84 | 84 |
|
85 | 85 | ```js run |
86 | 86 | let name = "John"; |
87 | 87 |
|
88 | | -// embed a variable |
89 | | -alert( `Hello, *!*${name}*/!*!` ); // Hello, John! |
| 88 | +// įterpti kintamąjį |
| 89 | +alert( `Labas, *!*${name}*/!*!` ); // Labas, John! |
90 | 90 |
|
91 | | -// embed an expression |
92 | | -alert( `the result is *!*${1 + 2}*/!*` ); // the result is 3 |
| 91 | +// įterpti išraišką |
| 92 | +alert( `rezultas yra *!*${1 + 2}*/!*` ); // rezultatas yra 3 |
93 | 93 | ``` |
94 | 94 |
|
95 | | -The expression inside `${…}` is evaluated and the result becomes a part of the string. We can put anything in there: a variable like `name` or an arithmetical expression like `1 + 2` or something more complex. |
| 95 | +Išraiška viduje `${…}` yra įvertinama ir rezultatas tampa eilutės dalimi. Mes galime įdėti bet ką: tokį kintamąjį kaip `name` arba aritmetinę išraišką kaip `1 + 2` arba ką nors dar sudėtingesnio. |
96 | 96 |
|
97 | | -Please note that this can only be done in backticks. Other quotes don't have this embedding functionality! |
| 97 | +Atkreipkite dėmesį, kad tai galima padaryti tik su atvirkštinėmis kabutėmis. Kitos kabutės neturi tokio įterpimo funkcionalumo! |
98 | 98 | ```js run |
99 | | -alert( "the result is ${1 + 2}" ); // the result is ${1 + 2} (double quotes do nothing) |
| 99 | +alert( "rezultatas yra ${1 + 2}" ); // rezultatas yra ${1 + 2} (dvigubos kabutės nieko nepadaro) |
100 | 100 | ``` |
101 | 101 |
|
102 | | -We'll cover strings more thoroughly in the chapter <info:string>. |
| 102 | +Mes kalbėsime daugiau apie eilutes skyriuje <info:string>. |
103 | 103 |
|
104 | | -```smart header="There is no *character* type." |
105 | | -In some languages, there is a special "character" type for a single character. For example, in the C language and in Java it is `char`. |
| 104 | +```smart header="Nėra tokio tipo kaip *ženklas*." |
| 105 | +Kai kuriose kalbose yra specialus "ženklo" (ang. character) tipas skirtas vienetiniam ženklui. Pavyzdžiui tokiose kalbose kaip C arba Java toks ženklas yra vadinamas `char`. |
106 | 106 |
|
107 | | -In JavaScript, there is no such type. There's only one type: `string`. A string may consist of only one character or many of them. |
| 107 | +JavaScript tokio tipo nėra. Yra tik vienas tipas: `string`(eilutė). Eilutė gali būti sudaryta iš vieno ženklo arba iš daug ženklų. |
108 | 108 | ``` |
109 | 109 |
|
110 | | -## A boolean (logical type) |
| 110 | +## Loginis tipas |
111 | 111 |
|
112 | | -The boolean type has only two values: `true` and `false`. |
| 112 | +Loginis tipas (ang. boolean) turi tik dvi reikšmes: `true` (tiesa) ir `false`(netiesa). |
113 | 113 |
|
114 | | -This type is commonly used to store yes/no values: `true` means "yes, correct", and `false` means "no, incorrect". |
| 114 | +Šis tipas dažniausiai naudojamas, kad išsaugotų taip/ne vertes: `true` reiškia "taip, teisingai", o `false` reiškia "ne, netesingai". |
115 | 115 |
|
116 | | -For instance: |
| 116 | +Pavyzdžiui: |
117 | 117 |
|
118 | 118 | ```js |
119 | | -let nameFieldChecked = true; // yes, name field is checked |
120 | | -let ageFieldChecked = false; // no, age field is not checked |
| 119 | +let nameFieldChecked = true; // taip, vardo laukelis pažymėtas |
| 120 | +let ageFieldChecked = false; // ne, amžiaus laukelis nepažymėtas |
121 | 121 | ``` |
122 | 122 |
|
123 | | -Boolean values also come as a result of comparisons: |
| 123 | +Loginės vertės taip pat yra palyginimų rezultatas: |
124 | 124 |
|
125 | 125 | ```js run |
126 | 126 | let isGreater = 4 > 1; |
127 | 127 |
|
128 | | -alert( isGreater ); // true (the comparison result is "yes") |
| 128 | +alert( isGreater ); // tiesa (palyginimo rezultatas yra "taip") |
129 | 129 | ``` |
130 | 130 |
|
131 | | -We'll cover booleans more deeply in the chapter <info:logical-operators>. |
| 131 | +Mes daugiau kalbėsime apie loginį tipą skyriuje <info:logical-operators>. |
132 | 132 |
|
133 | | -## The "null" value |
| 133 | +## "null" vertė |
134 | 134 |
|
135 | | -The special `null` value does not belong to any of the types described above. |
| 135 | +Ypatingoji `null` (negaliojanti) vertė nepriklauso jokiam anksčiau minėtam tipui. |
136 | 136 |
|
137 | | -It forms a separate type of its own which contains only the `null` value: |
| 137 | +Jis formuoja atskirą savo tipą, kuriame yra tik `null` vertė: |
138 | 138 |
|
139 | 139 | ```js |
140 | 140 | let age = null; |
141 | 141 | ``` |
142 | 142 |
|
143 | | -In JavaScript, `null` is not a "reference to a non-existing object" or a "null pointer" like in some other languages. |
| 143 | +JavaScript `null` nėra "nuoroda į neegzistuojantį objektą" arba į "nulinę užuomeną" (ang. "null pointer") kaip kai kurios kitos kalbos. |
144 | 144 |
|
145 | | -It's just a special value which represents "nothing", "empty" or "value unknown". |
| 145 | +Tai tik speciali vertė, kuri atstovauja "nieką", "tuštumą" arba "vertė nežinoma". |
146 | 146 |
|
147 | | -The code above states that `age` is unknown or empty for some reason. |
| 147 | +Kodas viršuje reiškia, kad `age` nėra žinomas arba tuščias dėl neaiškios priežasties. |
148 | 148 |
|
149 | 149 | ## The "undefined" value |
150 | 150 |
|
|
0 commit comments