You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/14-function-basics/article.md
+17-17Lines changed: 17 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -105,54 +105,54 @@ showMessage();
105
105
alert( userName ); // *!*Bob*/!*, vertė, pakeista funkcija
106
106
```
107
107
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.
109
109
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:
111
111
112
112
```js run
113
113
let userName ='John';
114
114
115
115
functionshowMessage() {
116
116
*!*
117
-
let userName ="Bob"; //declare a local variable
117
+
let userName ="Bob"; //deklaruojame vietinį kintamąjį
118
118
*/!*
119
119
120
-
let message ='Hello, '+ userName; // *!*Bob*/!*
120
+
let message ='Labas, '+ userName; // *!*Bob*/!*
121
121
alert(message);
122
122
}
123
123
124
-
//the function will create and use its own userName
124
+
//funkcija sukurs savo kintamąjį userName ir jį naudos
125
125
showMessage();
126
126
127
-
alert( userName ); // *!*John*/!*, unchanged, the function did not access the outer variable
127
+
alert( userName ); // *!*John*/!*, niekas nepasikeitė, funkcija nepakeitė išorinio kintamojo
128
128
```
129
129
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.
132
132
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ų).
134
134
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.
136
136
```
137
137
138
-
## Parameters
138
+
## Parametrai
139
139
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ą.
141
141
142
-
In the example below, the function has two parameters: `from`and`text`.
142
+
Žemiau pateiktame pavyzdyje funkcijai perduodami du argumentai: `from`ir`text`.
143
143
144
144
```js run
145
-
functionshowMessage(*!*from, text*/!*) { //arguments:from, text
145
+
functionshowMessage(*!*from, text*/!*) { //argumentai:from, text
showMessage('Ana', "Kaip sekasi?"); // Ann: Kaip sekasi? (**)
152
152
*/!*
153
153
```
154
154
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.
156
156
157
157
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:
0 commit comments