Skip to content

Commit 45228da

Browse files
author
Veljko Pejović
authored
Update article.md
1 parent d5eb9a0 commit 45228da

File tree

1 file changed

+70
-67
lines changed

1 file changed

+70
-67
lines changed
Lines changed: 70 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,159 +1,162 @@
1-
# Code structure
1+
# Struktura koda
22

3-
The first thing we'll study is the building blocks of code.
3+
Prvo što ćemo proučiti pisanje blokova koda.
44

5-
## Statements
5+
## Iskazi
66

7-
Statements are syntax constructs and commands that perform actions.
7+
Iskazi su sintaksne konstrukcije i naredbe koje izvode akcije.
88

9-
We've already seen a statement, `alert('Hello, world!')`, which shows the message "Hello, world!".
9+
Već smo viđeli iskaz, `alert('Zdravo svijete!')`, koja prikazuje poruku "Zdravo svijete!".
1010

11-
We can have as many statements in our code as we want. Statements can be separated with a semicolon.
11+
U kodu možemo imati onoliko iskaza koliko želimo. Iskazi se mogu odvojiti tačkom sa zarezom.
1212

13-
For example, here we split "Hello World" into two alerts:
13+
Na primer, ovde smo podelili "Zdravo svijete!" na dva upozorenja:
1414

1515
```js run no-beautify
16-
alert('Hello'); alert('World');
16+
alert('Zdravo'); alert('svijete!');
1717
```
1818

19-
Usually, statements are written on separate lines to make the code more readable:
19+
Iskazi se obično pišu u novim linijama kako bi se kod učinio čitljivijim:
2020

2121
```js run no-beautify
22-
alert('Hello');
23-
alert('World');
22+
alert('Zdravo');
23+
alert('svijete!');
2424
```
2525

26-
## Semicolons [#semicolon]
26+
## Tačka-zarez [#tackazarez]
2727

28-
A semicolon may be omitted in most cases when a line break exists.
28+
Tačka-zarez može biti izostavljena u većini slučajeva kada postoji prekid linije.
2929

30-
This would also work:
30+
Ovo bi takođe funkcionisalo:
3131

3232
```js run no-beautify
33-
alert('Hello')
34-
alert('World')
33+
alert('Zdravo')
34+
alert('svijete')
3535
```
3636

37-
Here, JavaScript interprets the line break as an "implicit" semicolon. This is called an [automatic semicolon insertion](https://tc39.github.io/ecma262/#sec-automatic-semicolon-insertion).
37+
Ovde JavaScript interpretira proboj prelom linija kao "implicitni" tačka-zarez. To se naziva [automatsko umetanje tačake-zareza]
38+
(https://tc39.github.io/ecma262/#sec-automatic-semicolon-insertion).
3839

39-
**In most cases, a newline implies a semicolon. But "in most cases" does not mean "always"!**
40+
**U većini slučajeva novi red podrazumeva tačku sa zarezom. Ali "u većini slučajeva" ne znači "uvjek"!**
4041

41-
There are cases when a newline does not mean a semicolon. For example:
42+
Postoje slučajevi kada nova linija ne znači tačka-zarez. Na primjer:
4243

4344
```js run no-beautify
4445
alert(3 +
4546
1
4647
+ 2);
4748
```
4849

49-
The code outputs `6` because JavaScript does not insert semicolons here. It is intuitively obvious that if the line ends with a plus `"+"`, then it is an "incomplete expression", so the semicolon is not required. And in this case that works as intended.
50+
Kod ispisuje `6`, jer JavaScript ovde ne ubacuje tačku-zarez. Intuitivno je očigledno da ako se linija završava sa plus "+" `, onda je to" nepotpun izraz ", pa tačka-zarez nije obavezna. I u ovom slučaju to radi onako kako je planirano.
5051

51-
**But there are situations where JavaScript "fails" to assume a semicolon where it is really needed.**
5252

53-
Errors which occur in such cases are quite hard to find and fix.
53+
**Ali postoje situacije u kojima JavaScript „ne uspijeva“ da pretpostavi tačku-zarez tamo gde je stvarno potrebno.
54+
**
5455

55-
````smart header="An example of an error"
56-
If you're curious to see a concrete example of such an error, check this code out:
56+
Greške koje se dešavaju u takvim slučajevima je stvarno teško otkriti i ispraviti.
57+
58+
````smart header="Primjer greške"
59+
Ako ste radoznali da vidite konkretan primer takve greške, pogledajte ovaj kod:
5760
5861
```js run
5962
[1, 2].forEach(alert)
6063
```
6164
62-
No need to think about the meaning of the brackets `[]` and `forEach` yet. We'll study them later. For now, just remember the result of the code: it shows `1` then `2`.
65+
Još nije potrebno razmišljati o značenju zagrada `[]` i `forEach`. Kasnije ćemo ih proučiti. Za sada se samo sjetite rezultata koda: prikazuje "1", a zatim "2".
6366
64-
Now, let's add an `alert` before the code and *not* finish it with a semicolon:
67+
Sada, dodajmo upozorenje prije koda i *ne* završimo tačkom-zarezom:
6568
6669
```js run no-beautify
67-
alert("There will be an error")
70+
alert("Ovđe će doći do greške")
6871
6972
[1, 2].forEach(alert)
7073
```
7174
72-
Now if we run the code, only the first `alert` is shown and then we have an error!
75+
Sada ako pokrenemo kod, prikazuje se samo prvo `upozorenje` i tada imamo grešku!
7376
74-
But everything is fine again if we add a semicolon after `alert`:
77+
Ali opet je sve u redu ako nakon `upozorenja` dodamo tačku-zarez:
7578
```js run
76-
alert("All fine now");
79+
alert("Sad je sve u redu!");
7780
7881
[1, 2].forEach(alert)
7982
```
8083
81-
Now we have the "All fine now" message followed by `1` and `2`.
84+
Sada imamo poruku "Sve u redu", a zatim slijede "1" i "2".
85+
8286
87+
Do greške u varijanti koja nije pod tačkom-zarezom događa se jer JavaScript ne podrazumeva tačku sa zarezom ispred uglastih zagrada `[...]`.
8388
84-
The error in the no-semicolon variant occurs because JavaScript does not assume a semicolon before square brackets `[...]`.
89+
Dakle, jer tačka-zarez nije automatski umetnuto, kod u prvom primeru se tretira kao jedna stavka. Evo kako motor to vidi:
8590
86-
So, because the semicolon is not auto-inserted, the code in the first example is treated as a single statement. Here's how the engine sees it:
8791
8892
```js run no-beautify
89-
alert("There will be an error")[1, 2].forEach(alert)
93+
alert("Ovđe će doći do greške!")[1, 2].forEach(alert)
9094
```
9195
92-
But it should be two separate statements, not one. Such a merging in this case is just wrong, hence the error. This can happen in other situations.
96+
Ali to bi trebalo biti dva odvojena iskaza, ne jedan. Takvo spajanje u ovom slučaju je upravo pogrešno, otuda i greška. To se može dogoditi i u drugim situacijama.
9397
````
9498

95-
We recommend putting semicolons between statements even if they are separated by newlines. This rule is widely adopted by the community. Let's note once again -- *it is possible* to leave out semicolons most of the time. But it's safer -- especially for a beginner -- to use them.
99+
Preporučujemo stavljanje tačke-zareza između izjava, čak i ako su razdvojene novim linijama. Ovo pravilo široko prihvata zajednica. Napomenimo još jednom - *moguće je* izostavljati tačku-zarez većinu vremena. Ali sigurnije je - posebno za početnike - koristiti ih.
96100

97-
## Comments
101+
## Komentari
98102

99-
As time goes on, programs become more and more complex. It becomes necessary to add *comments* which describe what the code does and why.
103+
Kako vrijeme prolazi, programi postaju sve složeniji. Potrebno je dodati *komentare* koji opisuju šta kod radi i zašto.
100104

101-
Comments can be put into any place of a script. They don't affect its execution because the engine simply ignores them.
105+
Komentari se mogu staviti na bilo koje mesto skripte. Oni ne utiču na njegovo izvršenje jer ih motor jednostavno ignoriše.
102106

103-
**One-line comments start with two forward slash characters `//`.**
107+
**Jednolinijski komentari počinju sa dvije prednje kose crte `//`.**
104108

105-
The rest of the line is a comment. It may occupy a full line of its own or follow a statement.
109+
Ostatak linije je komentar. Može zauzeti punu liniju ili slediti iskaz.
106110

107-
Like here:
111+
Kao što je ovđe:
108112
```js run
109-
// This comment occupies a line of its own
110-
alert('Hello');
113+
// Ovaj komentar zauzima sopstvenu liniju
114+
alert('Zdravo');
111115

112-
alert('World'); // This comment follows the statement
116+
alert('Svijete'); // Ovaj komentar prati iskaz
113117
```
114118

115-
**Multiline comments start with a forward slash and an asterisk <code>/&#42;</code> and end with an asterisk and a forward slash <code>&#42;/</code>.**
119+
**Višelinijski komentari počinju sa jednom prednjom kosom crtom i zvjezdicom <code>/&#42;</code> i završavaju se sa zvjezdicom i prednjom kosom crtom <code>&#42;/</code>.**
116120

117-
Like this:
121+
Kao što je ovo:
118122

119123
```js run
120-
/* An example with two messages.
121-
This is a multiline comment.
124+
/* Primjer sa dvije poruke
125+
Ovo je višelinijski komentar
122126
*/
123-
alert('Hello');
124-
alert('World');
127+
alert('Zdravo');
128+
alert('Svijete');
125129
```
126130

127-
The content of comments is ignored, so if we put code inside <code>/&#42; ... &#42;/</code>, it won't execute.
128-
129-
Sometimes it can be handy to temporarily disable a part of code:
131+
Sadržaj komentara se ignoriše, pa ako stavimo kod unutra <code>/&#42; ... &#42;/</code>, neće se izvršavati.
130132

133+
Ponekad je korisno privremeno deaktivirati deo koda:
131134
```js run
132-
/* Commenting out the code
133-
alert('Hello');
135+
/* Komentarisanje koda
136+
alert('Zdravo');
134137
*/
135-
alert('World');
138+
alert('Svijete');
136139
```
137140

138-
```smart header="Use hotkeys!"
139-
In most editors, a line of code can be commented out by pressing the `key:Ctrl+/` hotkey for a single-line comment and something like `key:Ctrl+Shift+/` -- for multiline comments (select a piece of code and press the hotkey). For Mac, try `key:Cmd` instead of `key:Ctrl`.
141+
```smart header="Korišćenje tastera za prečice!"
142+
U većini urednika koda se može komentarisati pritiskom na `taster:Ctrl+/` za jednolinijski komentar i nešto slično `taster:Ctrl+Shift+/` -- za komentare sa više linija (izaberite deo koda i pritisnite taster). Probajte za Mac računare `taster:Cmd` umjesto `taster:Ctrl`.
140143
```
141144

142-
````warn header="Nested comments are not supported!"
143-
There may not be `/*...*/` inside another `/*...*/`.
145+
````warn header="Uneseni komentari nisu podržani!"
146+
Ne može biti `/*...*/` u `/*...*/`.
144147
145-
Such code will die with an error:
148+
Takav kod bit će uništen greškom
146149
147150
```js run no-beautify
148151
/*
149-
/* nested comment ?!? */
152+
/* komentar u komentar ?!? */
150153
*/
151-
alert( 'World' );
154+
alert( 'Svijet' );
152155
```
153156
````
154157

155-
Please, don't hesitate to comment your code.
158+
Ne ustručavajte se da komentarišete svoj kod.
156159

157-
Comments increase the overall code footprint, but that's not a problem at all. There are many tools which minify code before publishing to a production server. They remove comments, so they don't appear in the working scripts. Therefore, comments do not have negative effects on production at all.
160+
Komentari povećavaju ukupni trag koda, ali to uopšte nije problem. Postoji mnogo alata koji minimiziraju kod prije objavljivanja na proizvodnom serveru. Oni uklanjaju komentare, tako da se ne pojavljuju u radnim skriptama. Stoga komentari uopšte nemaju negativne efekte na proizvodnju.
158161

159-
Later in the tutorial there will be a chapter <info:code-quality> that also explains how to write better comments.
162+
Kasnije će u udžbeniku biti poglavlja <info:code-quality> to takođe objašnjava kako napisati bolje komentare.

0 commit comments

Comments
 (0)