Skip to content

Commit 1e285b0

Browse files
authored
20%
1 parent 8d8bbca commit 1e285b0

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

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

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
11
# Functions
22

3-
Quite often we need to perform a similar action in many places of the script.
3+
Dažnai tą patį veiksmą reikia pakartoti daugelyje programos dalių.
44

5-
For example, we need to show a nice-looking message when a visitor logs in, logs out and maybe somewhere else.
5+
Pavyzdžiui, reikia parodyti lankytojui gražų pranešimą, kai jis įeina į svetainę, kai jis išeina iš svetainės arba bet kur kitur.
66

7-
Functions are the main "building blocks" of the program. They allow the code to be called many times without repetition.
7+
Siekiant išvengti to paties kodo kartojimo daugelyje vietų, buvo sugalvotos funkcijos. Funkcijos - tai pagrindiniai programos blokai.
88

9-
We've already seen examples of built-in functions, like `alert(message)`, `prompt(message, default)` and `confirm(question)`. But we can create functions of our own as well.
9+
Jus jau matėte integruotų funkcijų pavyzdžių - tai `alert(message)`, `prompt(message, default)` ir `confirm(question)`. Tačiau taip pat galima kurti savo funkcijas
1010

11-
## Function Declaration
11+
## Funkcijos deklaravimas
1212

13-
To create a function we can use a *function declaration*.
13+
Norėdami sukurti funkcijas, galime naudoti *funkcijos deklaravimų*.
1414

15-
It looks like this:
15+
Funkcijos deklaravimo pavyzdys:
1616

1717
```js
1818
function showMessage() {
19-
alert( 'Hello everyone!' );
19+
alert( 'Labas visiems!' );
2020
}
2121
```
2222

23-
The `function` keyword goes first, then goes the *name of the function*, then a list of *parameters* between the parentheses (comma-separated, empty in the example above) and finally the code of the function, also named "the function body", between curly braces.
23+
Pirmiausia įrašomas raktažodis `funkcija', po jo nurodomas funkcijos pavadinimas, po to skliausteliuose pateikiamas parametrų sąrašas, atskirtas kableliais (aukščiau pateiktame pavyzdyje jis yra tuščias), ir, galiausiai, funkcijos kodas, dar vadinamas «funkcijos turiniu», riestiniuose skliaustuose.
2424

2525
```js
2626
function name(parameters) {
2727
...body...
2828
}
2929
```
3030

31-
Our new function can be called by its name: `showMessage()`.
31+
Mūsų naująją funkciją galima iškviesti jos pavadinimu: `showMessage()`.
3232

33-
For instance:
33+
Pavyzdžiui:
3434

3535
```js run
3636
function showMessage() {
37-
alert( 'Hello everyone!' );
37+
alert( 'Labas visiems!' );
3838
}
3939

4040
*!*
@@ -43,66 +43,66 @@ showMessage();
4343
*/!*
4444
```
4545

46-
The call `showMessage()` executes the code of the function. Here we will see the message two times.
46+
Kai mes iškviečiame `showMessage()`, įvykdomas funkcijos kodas. Čia matysime pranešimą du kartus.
4747

48-
This example clearly demonstrates one of the main purposes of functions: to avoid code duplication.
48+
Šis pavyzdys aiškiai parodo vieną iš pagrindinių funkcijų tikslų - atsikratyti kodo dubliavimo.
4949

50-
If we ever need to change the message or the way it is shown, it's enough to modify the code in one place: the function which outputs it.
50+
Jei reikia pakeisti pranešimą arba jo išvedimo būdą, užteks pakeisti ją vienoje vietoje: funkcijoje, kuri išveda šį pranešimą.
5151

52-
## Local variables
52+
## Lokaliniai kintamieji
5353

54-
A variable declared inside a function is only visible inside that function.
54+
Funkcijoje deklaruoti kintamieji matomi tik toje funkcijoje.
5555

56-
For example:
56+
Pavyzdžiui:
5757

5858
```js run
5959
function showMessage() {
6060
*!*
61-
let message = "Hello, I'm JavaScript!"; // local variable
61+
let message = "Sveiki, aš esu JavaScript!"; // lokalinis kintamasis
6262
*/!*
6363

6464
alert( message );
6565
}
6666

67-
showMessage(); // Hello, I'm JavaScript!
67+
showMessage(); // Sveiki, aš esu JavaScript!
6868

6969
alert( message ); // <-- Error! The variable is local to the function
7070
```
7171

72-
## Outer variables
72+
## Išoriniai kintamieji
7373

74-
A function can access an outer variable as well, for example:
74+
Funkcija turi prieigą prie išorinių kintamųjų, pavyzdžiui:
7575

7676
```js run no-beautify
7777
let *!*userName*/!* = 'John';
7878

7979
function showMessage() {
80-
let message = 'Hello, ' + *!*userName*/!*;
80+
let message = 'Labas, ' + *!*userName*/!*;
8181
alert(message);
8282
}
8383

84-
showMessage(); // Hello, John
84+
showMessage(); // Labas, John
8585
```
8686

87-
The function has full access to the outer variable. It can modify it as well.
87+
Funkcija turi pilną prieigą prie išorinių kintamųjų ir gali keisti jų vertę.
8888

89-
For instance:
89+
Pavyzdžiui:
9090

9191
```js run
9292
let *!*userName*/!* = 'John';
9393

9494
function showMessage() {
95-
*!*userName*/!* = "Bob"; // (1) changed the outer variable
95+
*!*userName*/!* = "Bob"; // (1) keičiame išorinio kintamojo vertę
9696

97-
let message = 'Hello, ' + *!*userName*/!*;
97+
let message = 'Labas, ' + *!*userName*/!*;
9898
alert(message);
9999
}
100100

101-
alert( userName ); // *!*John*/!* before the function call
101+
alert( userName ); // *!*John*/!* prieš funkcijos iškvietimą
102102

103103
showMessage();
104104

105-
alert( userName ); // *!*Bob*/!*, the value was modified by the function
105+
alert( userName ); // *!*Bob*/!*, vertė, pakeista funkcija
106106
```
107107

108108
The outer variable is only used if there's no local one.

0 commit comments

Comments
 (0)