Skip to content

Commit b6d05e3

Browse files
authored
28%
1 parent 1e285b0 commit b6d05e3

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

1-js/02-first-steps/14-function-basics/article.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -105,54 +105,54 @@ showMessage();
105105
alert( userName ); // *!*Bob*/!*, vertė, pakeista funkcija
106106
```
107107

108-
The outer variable is only used if there's no local one.
108+
Išorinis kintamasis naudojamas tik tuo atveju, jei nėra lokalinio kintamojo.
109109

110-
If a same-named variable is declared inside the function then it *shadows* the outer one. For instance, in the code below the function uses the local `userName`. The outer one is ignored:
110+
Jei funkcijos viduje deklaruojame kintamąjį, kuris buvo deklaruotas už funkcijos ribų, išorinis kintamasis bus ignoruojamas. Pavyzdžiui, toliau pateiktame kode funkcija naudoja lokalinį kintamąjį `userName`. Išorinis bus ignoruojamas:
111111

112112
```js run
113113
let userName = 'John';
114114

115115
function showMessage() {
116116
*!*
117-
let userName = "Bob"; // declare a local variable
117+
let userName = "Bob"; // deklaruojame vietinį kintamąjį
118118
*/!*
119119

120-
let message = 'Hello, ' + userName; // *!*Bob*/!*
120+
let message = 'Labas, ' + userName; // *!*Bob*/!*
121121
alert(message);
122122
}
123123

124-
// the function will create and use its own userName
124+
// funkcija sukurs savo kintamąjį userName ir jį naudos
125125
showMessage();
126126

127-
alert( userName ); // *!*John*/!*, unchanged, the function did not access the outer variable
127+
alert( userName ); // *!*John*/!*, niekas nepasikeitė, funkcija nepakeitė išorinio kintamojo
128128
```
129129

130-
```smart header="Global variables"
131-
Variables declared outside of any function, such as the outer `userName` in the code above, are called *global*.
130+
```smart header="Globalūs kintamieji"
131+
Kintamieji, deklaruojami už visų funkcijų ribų, pvz., išorinis kintamasis `userName` aukščiau pateiktame kode, vadinami globaliaisiais.
132132
133-
Global variables are visible from any function (unless shadowed by locals).
133+
Globalūs kintamieji matomi bet kurioje funkcijoje (nebent tose funkcijose yra to paties pavadinimo kintamųjų).
134134
135-
It's a good practice to minimize the use of global variables. Modern code has few or no globals. Most variables reside in their functions. Sometimes though, they can be useful to store project-level data.
135+
Patartina kuo mažiau naudoti globaliuosius kintamuosius. Šiuolaikiniame kode paprastai globalių kintamųjų būna nedaug arba jų iš viso nebūna. Nors kartais jos yra naudingos svarbiausiems projekto duomenims saugoti.
136136
```
137137

138-
## Parameters
138+
## Parametrai
139139

140-
We can pass arbitrary data to functions using parameters (also called *function arguments*) .
140+
Naudodami parametrus (dar vadinamus *funkcijos argumentais*) funkcijai galime perduoti bet kokią informaciją.
141141

142-
In the example below, the function has two parameters: `from` and `text`.
142+
Žemiau pateiktame pavyzdyje funkcijai perduodami du argumentai: `from` ir `text`.
143143

144144
```js run
145-
function showMessage(*!*from, text*/!*) { // arguments: from, text
145+
function showMessage(*!*from, text*/!*) { // argumentai: from, text
146146
alert(from + ': ' + text);
147147
}
148148

149149
*!*
150-
showMessage('Ann', 'Hello!'); // Ann: Hello! (*)
151-
showMessage('Ann', "What's up?"); // Ann: What's up? (**)
150+
showMessage('Ana', 'Sveiki!'); // Ann: Sveiki! (*)
151+
showMessage('Ana', "Kaip sekasi?"); // Ann: Kaip sekasi? (**)
152152
*/!*
153153
```
154154
155-
When the function is called in lines `(*)` and `(**)`, the given values are copied to local variables `from` and `text`. Then the function uses them.
155+
Kai funkcija iškviečiama eilutėse `(*)` ir `(**)`, perduotos vertės perkeliamos į lokalinius kintamuosius from ir text. Tada jie naudojami funkcijos turinyje.
156156
157157
Here's one more example: we have a variable `from` and pass it to the function. Please note: the function changes `from`, but the change is not seen outside, because a function always gets a copy of the value:
158158

0 commit comments

Comments
 (0)