From 47ba77b2e8dc6cb7226b3c0e99800b34c1ab9db8 Mon Sep 17 00:00:00 2001 From: Aiyo <43038017+aiyodev@users.noreply.github.com> Date: Mon, 3 Aug 2020 21:55:11 +0200 Subject: [PATCH 01/11] Update article.md --- 1-js/02-first-steps/08-operators/article.md | 138 ++++++++++---------- 1 file changed, 69 insertions(+), 69 deletions(-) diff --git a/1-js/02-first-steps/08-operators/article.md b/1-js/02-first-steps/08-operators/article.md index 48c453cec..476ab4c57 100644 --- a/1-js/02-first-steps/08-operators/article.md +++ b/1-js/02-first-steps/08-operators/article.md @@ -1,15 +1,15 @@ -# Basic operators, maths +# Osnovni operatori, matematika -We know many operators from school. They are things like addition `+`, multiplication `*`, subtraction `-`, and so on. +Mi znamo mnoge operatore iz škole. To su stvari kao što su sabiranje `+`, množenje `*`, oduzimanje `-`, i tako dalje. -In this chapter, we’ll start with simple operators, then concentrate on JavaScript-specific aspects, not covered by school arithmetic. +U ovom poglavlju, započet ćemo sa jednostavnim operatorima, pa ćemo se onda koncentrisati na one JavaScript specifične aspekte, koji nisu spomenuti u školi. -## Terms: "unary", "binary", "operand" +## Pojmovi: "unary", "binary", "operand" -Before we move on, let's grasp some common terminology. +Prije nego što krenemo, trebamo shvatiti opštu terminologiju. -- *An operand* -- is what operators are applied to. For instance, in the multiplication of `5 * 2` there are two operands: the left operand is `5` and the right operand is `2`. Sometimes, people call these "arguments" instead of "operands". -- An operator is *unary* if it has a single operand. For example, the unary negation `-` reverses the sign of a number: +- *Operand* -- je ono na šta se operatori primjenjuju. Na primjer, u množenju `5 * 2` imamo dva operanda: lijevi operand je `5` a desni je `2`. Ponekad, ljudi ih nazivaju "argument" umjesto "operand". +- Operator je *unary* (matematička operacija koja uključuje samo jedan element) ako ima samo jedan operand. Na primjer, unary negacija `-` mijenja predznak broja: ```js run let x = 1; @@ -17,114 +17,114 @@ Before we move on, let's grasp some common terminology. *!* x = -x; */!* - alert( x ); // -1, unary negation was applied + alert( x ); // -1, unary negacija je primjenjena ``` -- An operator is *binary* if it has two operands. The same minus exists in binary form as well: +- Operator je *binary* (binarni, uključuje dva elementa) ako ima dva operanda. Isti minus postoji u binarnoj formi: ```js run no-beautify let x = 1, y = 3; - alert( y - x ); // 2, binary minus subtracts values + alert( y - x ); // 2, binarni minus oduzima vrijednosti ``` - Formally, in the examples above we have two different operators that share the same symbol: the negation operator, a unary operator that reverses the sign, and the subtraction operator, a binary operator that subtracts one number from another. + Formalno rečeno, u primjerima iznad imamo dva različita operatora koji dijele isti simbol: operator negacije, unary operator koji mijenja predznak, i operator oduzimanja, binarni operator koji oduzima jedan broj od drugog. -## Maths +## Matematika -The following math operations are supported: +Sljedeće matematičke operacije su podržane: -- Addition `+`, -- Subtraction `-`, -- Multiplication `*`, -- Division `/`, -- Remainder `%`, -- Exponentiation `**`. +- Sabiranje `+`, +- Oduzimanje `-`, +- Množenje `*`, +- Dijeljenje `/`, +- Ostatak `%`, +- Eksponencija `**`. -The first four are straightforward, while `%` and `**` need a few words about them. +Prva četiri su jednostavna, dok o `%` i `**` trebamo nešto reći. -### Remainder % +### Ostatak % -The remainder operator `%`, despite its appearance, is not related to percents. +Operator za ostatak `%`, uprkos svom izgledu, nije povezan sa postotcima. -The result of `a % b` is the [remainder](https://en.wikipedia.org/wiki/Remainder) of the integer division of `a` by `b`. +Rezultat `a % b` je [ostatak](https://en.wikipedia.org/wiki/Remainder) prilikom cjelobrojne podjele `a` sa `b`. -For instance: +Na primjer: ```js run -alert( 5 % 2 ); // 1, a remainder of 5 divided by 2 -alert( 8 % 3 ); // 2, a remainder of 8 divided by 3 +alert( 5 % 2 ); // 1, ostatak prilikom dijeljenja 5 sa 2 +alert( 8 % 3 ); // 2, ostatak prilikom dijeljenja 8 sa 3 ``` -### Exponentiation ** +### Eksponencija ** -The exponentiation operator `a ** b` multiplies `a` by itself `b` times. +Operator eksponencije `a ** b` množi `a` sa sobom `b` puta. -For instance: +Na primjer: ```js run -alert( 2 ** 2 ); // 4 (2 multiplied by itself 2 times) -alert( 2 ** 3 ); // 8 (2 * 2 * 2, 3 times) -alert( 2 ** 4 ); // 16 (2 * 2 * 2 * 2, 4 times) +alert( 2 ** 2 ); // 4 (2 pomnoženo sa sobom 2 puta) +alert( 2 ** 3 ); // 8 (2 * 2 * 2, 3 puta) +alert( 2 ** 4 ); // 16 (2 * 2 * 2 * 2, 4 puta) ``` -Mathematically, the exponentiation is defined for non-integer numbers as well. For example, a square root is an exponentiation by `1/2`: +Matematički, eksponencija je određena i za ne-cijele brojeve. Na primjer, korijen je eksponencija od `1/2`: ```js run -alert( 4 ** (1/2) ); // 2 (power of 1/2 is the same as a square root) -alert( 8 ** (1/3) ); // 2 (power of 1/3 is the same as a cubic root) +alert( 4 ** (1/2) ); // 2 (stepen od 1/2 je isti kao i kvadratni korijen) +alert( 8 ** (1/3) ); // 2 (stepen od 1/3 je isti kao kubični korijen) ``` -## String concatenation with binary + +## Spajanje stringova sa binarnim + -Let's meet features of JavaScript operators that are beyond school arithmetics. +Upoznajmo se sa mogućnostima JavaScript operatora koji su izvan školske aritmetike. -Usually, the plus operator `+` sums numbers. +Obično, plus operator `+` sabira brojeve. -But, if the binary `+` is applied to strings, it merges (concatenates) them: +Ali, ako se binarni `+` primijeni na string-ove, spaja ih: ```js let s = "my" + "string"; alert(s); // mystring ``` -Note that if any of the operands is a string, then the other one is converted to a string too. +Zapamtite da ako je bilo koji operand string, onda će se drugi također pretvoriti u string. -For example: +Na primjer: ```js run alert( '1' + 2 ); // "12" alert( 2 + '1' ); // "21" ``` -See, it doesn't matter whether the first operand is a string or the second one. +Vidite, nije bitno da je li prvi ili drugi operand string. -Here's a more complex example: +Evo jedan kompleksniji primjer: ```js run -alert(2 + 2 + '1' ); // "41" and not "221" +alert(2 + 2 + '1' ); // "41" a ne "221" ``` -Here, operators work one after another. The first `+` sums two numbers, so it returns `4`, then the next `+` adds the string `1` to it, so it's like `4 + '1' = 41`. +Ovdje, operatori rade jedan poslije drugog. Prvi `+` sabira dva broja, tako da vraća `4`, onda sljedeći `+` dodaje string `1`, tako da bude `4 + '1' = 41`. -The binary `+` is the only operator that supports strings in such a way. Other arithmetic operators work only with numbers and always convert their operands to numbers. +Binarni `+` je jedini operator koji podržava string-ove na ovaj način. Ostali aritmetički operatori rade samo sa brojevima i uvijek pretvaraju operand-e u brojeve. -Here's the demo for subtraction and division: +Evo šta se desi ako oduzimamo i dijelimo: ```js run -alert( 6 - '2' ); // 4, converts '2' to a number -alert( '6' / '2' ); // 3, converts both operands to numbers +alert( 6 - '2' ); // 4, pretvara '2' u broj +alert( '6' / '2' ); // 3, pretvara oba operand-a u brojeve ``` -## Numeric conversion, unary + +## Numerična konverzija, unary + -The plus `+` exists in two forms: the binary form that we used above and the unary form. +`+` postoji u dvije forme: binarna forma koju smo koristili iznad i unary forma. -The unary plus or, in other words, the plus operator `+` applied to a single value, doesn't do anything to numbers. But if the operand is not a number, the unary plus converts it into a number. +Unary plus, ili u drugim riječima, plus operator `+` koji je primijenjen na samo jednu vrijednost, ne radi ništa brojevimna. Ali ako operand nije broj, unary plus ga pretvara u broj. For example: ```js run -// No effect on numbers +// Nema uticaj na brojeve let x = 1; alert( +x ); // 1 @@ -132,55 +132,55 @@ let y = -2; alert( +y ); // -2 *!* -// Converts non-numbers +// Pretvara vrijednosti koje nisu brojevi alert( +true ); // 1 alert( +"" ); // 0 */!* ``` -It actually does the same thing as `Number(...)`, but is shorter. +Radi istu stvar kao `Number(...)`, ali je kraće. -The need to convert strings to numbers arises very often. For example, if we are getting values from HTML form fields, they are usually strings. What if we want to sum them? +Potreba za pretvaranje string-ova u brojeve se javlja veoma često. Na primjer, ako dobijamo vrijednosti iz HTML polja za unos, one su obično string-ovi. Šta ako želimo da ih saberemo? -The binary plus would add them as strings: +Binarni plus će ih dodati kao string-ove: ```js run let apples = "2"; let oranges = "3"; -alert( apples + oranges ); // "23", the binary plus concatenates strings +alert( apples + oranges ); // "23", binarni plus spaja string-ove ``` -If we want to treat them as numbers, we need to convert and then sum them: +Ako ih želimo tretirati kao brojeve, moramo ih pretvoriti i sabrati: ```js run let apples = "2"; let oranges = "3"; *!* -// both values converted to numbers before the binary plus +// obe vrijednosti su pretvorene u brojeve prije binarnog plusa alert( +apples + +oranges ); // 5 */!* -// the longer variant +// duža varijanta // alert( Number(apples) + Number(oranges) ); // 5 ``` -From a mathematician's standpoint, the abundance of pluses may seem strange. But from a programmer's standpoint, there's nothing special: unary pluses are applied first, they convert strings to numbers, and then the binary plus sums them up. +Sa stanovišta matematičara, obilje pluseva možda zvuči čudno. Ali sa stanovišta programera, to nije ništa specijalno: unary plusevi se prvo primijenjuju, oni pretvaraju string-ove u brojeve, pa ih tek onda binarni plus sabira. -Why are unary pluses applied to values before the binary ones? As we're going to see, that's because of their *higher precedence*. +Zašto su unary plusevi primijenjeni na vrijednosti prije binarnih? To ćemo naučiti ubrzo, razlog toga jeste njihov *veći prioritet*. -## Operator precedence +## Prioritet operatora -If an expression has more than one operator, the execution order is defined by their *precedence*, or, in other words, the default priority order of operators. +Ako izraz ima više od jednog operatora, onda je red izvršavanja određen njihovim *prioritetima*, ili, u drugim riječima, uobičajenim redom prioriteta operatora. -From school, we all know that the multiplication in the expression `1 + 2 * 2` should be calculated before the addition. That's exactly the precedence thing. The multiplication is said to have *a higher precedence* than the addition. +Iz škole, svi znamo da množenje u izrazu `1 + 2 * 2` treba biti izračunato prije sabiranja. To je tačno ova stvar o prioritetima. Množenje ima *veći prioritet* od sabiranja. -Parentheses override any precedence, so if we're not satisfied with the default order, we can use them to change it. For example, write `(1 + 2) * 2`. +Zagrade nadjačavaju prioritete, tako da ako nismo zadovoljni sa uobičajenim redom, možemo koristiti iste da promijenimo red. Na primjer, napišite `(1 + 2) * 2`. -There are many operators in JavaScript. Every operator has a corresponding precedence number. The one with the larger number executes first. If the precedence is the same, the execution order is from left to right. +Postoji mnogo operatora u JavaScript-u. Svaki operator ima određeni nivo prioriteta. Onaj sa većim nivoom se prvi izvršava. Ako je prioritet isti, red izvršavanja je od lijeve ka desnoj strani. -Here's an extract from the [precedence table](https://developer.mozilla.org/en/JavaScript/Reference/operators/operator_precedence) (you don't need to remember this, but note that unary operators are higher than corresponding binary ones): +Evo ekstrakta iz [tabele prioriteta](https://developer.mozilla.org/en/JavaScript/Reference/operators/operator_precedence) (ne trebate ovo zapamtiti, ali zapamtite samo da su unary operatori veći od odgovarajućeg binarnog): | Precedence | Name | Sign | |------------|------|------| From 876dc4aa01a09a18352fbffb80a05fc2bdad5168 Mon Sep 17 00:00:00 2001 From: Aiyo <43038017+aiyodev@users.noreply.github.com> Date: Mon, 3 Aug 2020 21:55:56 +0200 Subject: [PATCH 02/11] Update article.md --- 1-js/02-first-steps/08-operators/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/08-operators/article.md b/1-js/02-first-steps/08-operators/article.md index 476ab4c57..d4ac21025 100644 --- a/1-js/02-first-steps/08-operators/article.md +++ b/1-js/02-first-steps/08-operators/article.md @@ -121,7 +121,7 @@ alert( '6' / '2' ); // 3, pretvara oba operand-a u brojeve Unary plus, ili u drugim riječima, plus operator `+` koji je primijenjen na samo jednu vrijednost, ne radi ništa brojevimna. Ali ako operand nije broj, unary plus ga pretvara u broj. -For example: +Na primjer: ```js run // Nema uticaj na brojeve From ec3c241dc9e4d7939222354b9cf3925641550101 Mon Sep 17 00:00:00 2001 From: Aiyo <43038017+aiyodev@users.noreply.github.com> Date: Tue, 4 Aug 2020 12:00:43 +0200 Subject: [PATCH 03/11] Update article.md --- 1-js/02-first-steps/08-operators/article.md | 164 ++++++++++---------- 1 file changed, 82 insertions(+), 82 deletions(-) diff --git a/1-js/02-first-steps/08-operators/article.md b/1-js/02-first-steps/08-operators/article.md index d4ac21025..b2dc2e6d9 100644 --- a/1-js/02-first-steps/08-operators/article.md +++ b/1-js/02-first-steps/08-operators/article.md @@ -182,27 +182,27 @@ Postoji mnogo operatora u JavaScript-u. Svaki operator ima određeni nivo priori Evo ekstrakta iz [tabele prioriteta](https://developer.mozilla.org/en/JavaScript/Reference/operators/operator_precedence) (ne trebate ovo zapamtiti, ali zapamtite samo da su unary operatori veći od odgovarajućeg binarnog): -| Precedence | Name | Sign | +| Prioritet | Ime | Znak | |------------|------|------| | ... | ... | ... | | 17 | unary plus | `+` | -| 17 | unary negation | `-` | -| 16 | exponentiation | `**` | -| 15 | multiplication | `*` | -| 15 | division | `/` | -| 13 | addition | `+` | -| 13 | subtraction | `-` | +| 17 | unary negacija | `-` | +| 16 | eksponencija | `**` | +| 15 | množenje | `*` | +| 15 | dijeljenje | `/` | +| 13 | sabiranje | `+` | +| 13 | oduzimanje | `-` | | ... | ... | ... | -| 3 | assignment | `=` | +| 3 | dodjela | `=` | | ... | ... | ... | -As we can see, the "unary plus" has a priority of `17` which is higher than the `13` of "addition" (binary plus). That's why, in the expression `"+apples + +oranges"`, unary pluses work before the addition. +Kao što možemo da vidimo, "unary plus" ima prioritet `17` koji je veći od `13` prioriteta "sabiranja" (binarni plus). Zato, u izrazu `"+apples + +oranges"`, unary plus se prije sabiranja izvršava. -## Assignment +## Dodjela -Let's note that an assignment `=` is also an operator. It is listed in the precedence table with the very low priority of `3`. - -That's why, when we assign a variable, like `x = 2 * 2 + 1`, the calculations are done first and then the `=` is evaluated, storing the result in `x`. +Zapamtite da je dodjela `=` isto operator. Na listi prioriteta ima mali prioritet `3`. + +Zato, kada dodijelimo vrijednost varijabli, `x = 2 * 2 + 1`, kalkulacije su izvršene prvo pa je `=` evaluiran, pohranjujući rezultat u varijablu `x`. ```js let x = 2 * 2 + 1; @@ -210,15 +210,15 @@ let x = 2 * 2 + 1; alert( x ); // 5 ``` -### Assignment = returns a value +### Dodjela = vraća vrijednost -The fact of `=` being an operator, not a "magical" language construct has an interesting implication. +Činjenica da je `=` operator, a ne "magični" jezički konstrukt ima interesantnu implikaciju. -Most operators in JavaScript return a value. That's obvious for `+` and `-`, but also true for `=`. +Većina operatora u JavaScript-u vraćaju vrijednost. To je očigledno za `+` i `-`, ali to isto vrijedi za `=`. -The call `x = value` writes the `value` into `x` *and then returns it*. +Poziv `x = value` piše `value` u `x` *pa je vraća*. -Here's a demo that uses an assignment as part of a more complex expression: +Evo primjera gdje se koristi operator dodjele kao dio složenog izraza: ```js run let a = 1; @@ -232,15 +232,15 @@ alert( a ); // 3 alert( c ); // 0 ``` -In the example above, the result of expression `(a = b + 1)` is the value which was assigned to `a` (that is `3`). It is then used for further evaluations. +U primjeru iznad, rezultat izraza `(a = b + 1)` je vrijednost koja je dodijeljena `a` (to je `3`). -Funny code, isn't it? We should understand how it works, because sometimes we see it in JavaScript libraries. +Smiješan kod, zar ne? Trebamo shvatiti kako radi, jer ga ponekad vidimo u JavaScript bibliotekama (eng. libraries). -Although, please don't write the code like that. Such tricks definitely don't make code clearer or readable. +Uprkos tome, ne pišite kod na taj način. Takvi trikovi sigurno ne čine da kod bude jasniji ili čitljiviji. -### Chaining assignments +### Lančanje dodjela -Another interesting feature is the ability to chain assignments: +Još jedna interesantna mogućnost jeste sposobnost da lančamo dodjele (eng. chain assignments): ```js run let a, b, c; @@ -254,20 +254,20 @@ alert( b ); // 4 alert( c ); // 4 ``` -Chained assignments evaluate from right to left. First, the rightmost expression `2 + 2` is evaluated and then assigned to the variables on the left: `c`, `b` and `a`. At the end, all the variables share a single value. +Lančane dodjele se evaluiraju s desna na lijevo. Prvo, najdesniji izraz `2 + 2` je evaluiran pa je dodijeljen varijablama na lijevoj strani: `c`, `b` i `a`. Na kraju, sve varijable dijele istu vrijednost. -Once again, for the purposes of readability it's better to split such code into few lines: +Još jednom, kako bi naš kod bio čitljiviji, bolje ga je podijeliti u nekoliko linija: ```js c = 2 + 2; b = c; a = c; ``` -That's easier to read, especially when eye-scanning the code fast. +Ovo je lakše za čitati, posebno kada brzo pregledavamo kod. -## Modify-in-place +## Modificiranje u mjestu (eng. modify-in-place) -We often need to apply an operator to a variable and store the new result in that same variable. +Mi često trebamo primijeniti operator na nekoj varijabli i pohraniti novi rezultat u istoj varijabli. For example: @@ -277,67 +277,67 @@ n = n + 5; n = n * 2; ``` -This notation can be shortened using the operators `+=` and `*=`: +Ova notacija može biti skraćena koristeći operatore `+=` i `*=`: ```js run let n = 2; -n += 5; // now n = 7 (same as n = n + 5) -n *= 2; // now n = 14 (same as n = n * 2) +n += 5; // sada n = 7 (isto kao n = n + 5) +n *= 2; // now n = 14 (isto kao n = n * 2) alert( n ); // 14 ``` -Short "modify-and-assign" operators exist for all arithmetical and bitwise operators: `/=`, `-=`, etc. +Kratki "modificiraj-i-dodijeli" operatori postoje za sve aritmetičke i bitwise operatore: `/=`, `-=`, itd. -Such operators have the same precedence as a normal assignment, so they run after most other calculations: +Takvi operatori imaju isti prioritet kao i prilikom normalnog dodijeljivanja, tako da su oni izvršeni poslije većine drugih kalkulacija: ```js run let n = 2; n *= 3 + 5; -alert( n ); // 16 (right part evaluated first, same as n *= 8) +alert( n ); // 16 (desni dio je prvi evaluiran, isto kao n *= 8) ``` -## Increment/decrement +## Povećavanje/smanjivanje (eng. increment/decrement) -Increasing or decreasing a number by one is among the most common numerical operations. +Povećavanje ili smanjivanje broja za jedan je skoro najčešća numerička operacija. -So, there are special operators for it: +Postoje specijalni operatori za ovu svrhu: -- **Increment** `++` increases a variable by 1: +- **Povećavanje** `++` povećava varijablu za 1: ```js run no-beautify let counter = 2; - counter++; // works the same as counter = counter + 1, but is shorter + counter++; // radi isto kao counter = counter + 1, ali je kraće alert( counter ); // 3 ``` -- **Decrement** `--` decreases a variable by 1: +- **Smanjivanje** `--` smanjuje varijablu za 1: ```js run no-beautify let counter = 2; - counter--; // works the same as counter = counter - 1, but is shorter + counter--; // radi isto kao counter = counter - 1, ali je kraće alert( counter ); // 1 ``` ```warn -Increment/decrement can only be applied to variables. Trying to use it on a value like `5++` will give an error. +Povećavanje/smanjivanje se može primijeniti samo na varijablama. Ako ih pokušamo koristiti na nekoj vrijednosti kao što je `5++` dobit ćemo grešku. ``` -The operators `++` and `--` can be placed either before or after a variable. +Operatori `++` i `--` mogu biti postavljeni ili prije ili poslije varijable. -- When the operator goes after the variable, it is in "postfix form": `counter++`. -- The "prefix form" is when the operator goes before the variable: `++counter`. +- Kada se operator nalazi iza varijable, nalazi se u tzv. "postfix formi": `counter++`. +- "Prefix forma" je kada se operator nalazi ispred varijable: `++counter`. -Both of these statements do the same thing: increase `counter` by `1`. +Obe ove izjave rade istu stvar: povećavaju `counter` za `1`. -Is there any difference? Yes, but we can only see it if we use the returned value of `++/--`. +Ima li razlike? Da, ali možemo je samo vidjeti ako koristimo vraćenu vrijednost od `++/--`. -Let's clarify. As we know, all operators return a value. Increment/decrement is no exception. The prefix form returns the new value while the postfix form returns the old value (prior to increment/decrement). +Hajmo razjasniti. Kao što znamo, svi operatori vraćaju vrijednost. Povećavanje/smanjivanje nije izuzetak. Prefix forma vraća novu vrijednost dok postfix forma vraća staru vrijednost (prije povećavanja ili smanjivanja). -To see the difference, here's an example: +Da vidimo razliku, evo primjera: ```js run let counter = 1; @@ -346,44 +346,44 @@ let a = ++counter; // (*) alert(a); // *!*2*/!* ``` -In the line `(*)`, the *prefix* form `++counter` increments `counter` and returns the new value, `2`. So, the `alert` shows `2`. +Na liniji `(*)`, *prefix* forma `++counter` povećava `counter` i vraća novu vrijednost, `2`. Tako da `alert` prikazuje `2`. -Now, let's use the postfix form: +Sada, hajmo koristiti postfix formu: ```js run let counter = 1; -let a = counter++; // (*) changed ++counter to counter++ +let a = counter++; // (*) promijenjeno sa ++counter na counter++ alert(a); // *!*1*/!* ``` -In the line `(*)`, the *postfix* form `counter++` also increments `counter` but returns the *old* value (prior to increment). So, the `alert` shows `1`. +Na liniji `(*)`, postfix forma `counter++` isto povećava `counter` ali vraća *staru* vrijednost (prije povećavanja). Tako da `alert` prikazuje `1`. -To summarize: +Da rezimiramo: -- If the result of increment/decrement is not used, there is no difference in which form to use: +- Ako rezultat povećavanja/smanjivanja nije korišten, nema razlike u tome koju formu koristite: ```js run let counter = 0; counter++; ++counter; - alert( counter ); // 2, the lines above did the same + alert( counter ); // 2, linije iznad su uradile isto ``` -- If we'd like to increase a value *and* immediately use the result of the operator, we need the prefix form: +- Ako želimo povećati vrijednost *i* odmah koristiti rezultat operatora, treba nam prefix forma: ```js run let counter = 0; alert( ++counter ); // 1 ``` -- If we'd like to increment a value but use its previous value, we need the postfix form: +- Ako želimo povećati vrijednost ali koristiti prethodnu, treba nam postfix forma: ```js run let counter = 0; alert( counter++ ); // 0 ``` -````smart header="Increment/decrement among other operators" -The operators `++/--` can be used inside expressions as well. Their precedence is higher than most other arithmetical operations. +````smart header="Povećavanje/smanjivanje među drugim operatorima" +Operatori `++/--` se mogu koristiti unutar izraza. Njihov prioritet je veći od većine drugih aritmetičkih operacija. For instance: @@ -392,18 +392,18 @@ let counter = 1; alert( 2 * ++counter ); // 4 ``` -Compare with: +Poredite sa: ```js run let counter = 1; -alert( 2 * counter++ ); // 2, because counter++ returns the "old" value +alert( 2 * counter++ ); // 2, jer counter++ vraća "staru" vrijednost ``` -Though technically okay, such notation usually makes code less readable. One line does multiple things -- not good. +Iako je tehnički ispravno, takva notacija čini kod manje čitljivijim. Jedna linija radi više stvari -- to nije u redu. -While reading code, a fast "vertical" eye-scan can easily miss something like `counter++` and it won't be obvious that the variable increased. +Kada čitamo kod, brzim "vertikalnim" prelazom preko istog možemo lagano izostaviti nešto kao `counter++` i neće biti očigledno da je varijabla povećana. -We advise a style of "one line -- one action": +Mi preporučujemo stil "jedna linija -- jedna akcija": ```js run let counter = 1; @@ -412,13 +412,13 @@ counter++; ``` ```` -## Bitwise operators +## Bitwise operatori -Bitwise operators treat arguments as 32-bit integer numbers and work on the level of their binary representation. +Bitwise operatori tretiraju argumente kao 32-bitne cijele brojeve i rade na nivou njihove binarne reprezentacije. -These operators are not JavaScript-specific. They are supported in most programming languages. +Ovi operatori nisu specifični za JavaScript. Oni su podržani u većini drugih programskih jezika. -The list of operators: +Lista operatora: - AND ( `&` ) - OR ( `|` ) @@ -428,13 +428,13 @@ The list of operators: - RIGHT SHIFT ( `>>` ) - ZERO-FILL RIGHT SHIFT ( `>>>` ) -These operators are used very rarely, when we need to fiddle with numbers on the very lowest (bitwise) level. We won't need these operators any time soon, as web development has little use of them, but in some special areas, such as cryptography, they are useful. You can read the [Bitwise Operators](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators) article on MDN when a need arises. +Ovi operatori se veoma rijetko koriste, kada trebamo da radimo sa brojevima na veoma niskom (bitwise) nivou. Ovi operatori nam neće trebati u bližoj budućnosti, jer u web programiranju imaju malu upotrebu, ali u nekim specijalnim oblastima kao što su kriptografija, su korisni. Možete pročitati [Bitwise Operatori](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators) poglavlje na MDN kada vam zatreba. -## Comma +## Zarez (eng. comma) -The comma operator `,` is one of the rarest and most unusual operators. Sometimes, it's used to write shorter code, so we need to know it in order to understand what's going on. +Zarez operator `,` je jedan od najrjeđih i najneobičnijih operatora. Ponekad se koristi da pišemo kraći kod, tako da ga trebamo naučiti da znamo šta on zapravo radi. -The comma operator allows us to evaluate several expressions, dividing them with a comma `,`. Each of them is evaluated but only the result of the last one is returned. +Zarez operator nam omogućava da evaluiramo više izraza, odvajajući ih zarezima `,`. Svaki od ovih izraza je evaluiran ali je vraćen samo rezultat posljednjeg. For example: @@ -446,25 +446,25 @@ let a = (1 + 2, 3 + 4); alert( a ); // 7 (the result of 3 + 4) ``` -Here, the first expression `1 + 2` is evaluated and its result is thrown away. Then, `3 + 4` is evaluated and returned as the result. +Ovdje, prvi izraz `1 + 2` je evaluiran i njegov rezultat je bačen. Onda, `3 + 4` je evaluiran i vraćen je rezultat. -```smart header="Comma has a very low precedence" -Please note that the comma operator has very low precedence, lower than `=`, so parentheses are important in the example above. +```smart header="Zarez ima veoma nizak prioritet" +Zapamtite da zarez operator ima veoma nizak prioritet, čak i manji od `=`, tako da su zagrade bitne u primjeru iznad. -Without them: `a = 1 + 2, 3 + 4` evaluates `+` first, summing the numbers into `a = 3, 7`, then the assignment operator `=` assigns `a = 3`, and the rest is ignored. It's like `(a = 1 + 2), 3 + 4`. +Bez njih: `a = 1 + 2, 3 + 4` evaluira `+` prvo, sabira brojeve pa dobijemo `a = 3, 7`, pa onda operator dodjele `=` dodijeli `a = 3`, a ostatak je ignorisan. Isto je kao `(a = 1 + 2), 3 + 4`. ``` -Why do we need an operator that throws away everything except the last expression? +Zašto nam onda treba operator koji baci sve osim zadnjeg izraza? -Sometimes, people use it in more complex constructs to put several actions in one line. +Ponekad, ljudi ga koriste u složenijim konstruktima kako bi stavili više akcija u jednu liniju. -For example: +Na primjer: ```js -// three operations in one line +// tri operacije u jednoj liniji for (*!*a = 1, b = 3, c = a * b*/!*; a < 10; a++) { ... } ``` -Such tricks are used in many JavaScript frameworks. That's why we're mentioning them. But usually they don't improve code readability so we should think well before using them. +Takvi trikovi se koriste u mnogo JavaScript framework-a. Zato ih spominjemo. Ali obično ne poboljšavaju čitljivost koda tako da trebamo dobro razmisliti prije nego što ih upotrijebimo. From 2cd814d927517d073f779653c4b7a34f7463324b Mon Sep 17 00:00:00 2001 From: Aiyo <43038017+aiyodev@users.noreply.github.com> Date: Tue, 4 Aug 2020 12:02:16 +0200 Subject: [PATCH 04/11] Update task.md --- 1-js/02-first-steps/08-operators/1-increment-order/task.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/1-js/02-first-steps/08-operators/1-increment-order/task.md b/1-js/02-first-steps/08-operators/1-increment-order/task.md index 7db092389..16f6c8a6f 100644 --- a/1-js/02-first-steps/08-operators/1-increment-order/task.md +++ b/1-js/02-first-steps/08-operators/1-increment-order/task.md @@ -1,10 +1,10 @@ -importance: 5 +važnost: 5 --- -# The postfix and prefix forms +# Postfix i prefix forme -What are the final values of all variables `a`, `b`, `c` and `d` after the code below? +Koje su finalne vrijednost varijabli `a`, `b`, `c` i `d` poslije koda ispod? ```js let a = 1, b = 1; From 6f40730fc3609d529b796c576c9077fc28058b9a Mon Sep 17 00:00:00 2001 From: Aiyo <43038017+aiyodev@users.noreply.github.com> Date: Tue, 4 Aug 2020 12:03:21 +0200 Subject: [PATCH 05/11] Update solution.md --- .../08-operators/1-increment-order/solution.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/1-js/02-first-steps/08-operators/1-increment-order/solution.md b/1-js/02-first-steps/08-operators/1-increment-order/solution.md index 8a44d798e..cee138c76 100644 --- a/1-js/02-first-steps/08-operators/1-increment-order/solution.md +++ b/1-js/02-first-steps/08-operators/1-increment-order/solution.md @@ -1,5 +1,5 @@ -The answer is: +Odgovor je: - `a = 2` - `b = 2` @@ -9,10 +9,10 @@ The answer is: ```js run no-beautify let a = 1, b = 1; -alert( ++a ); // 2, prefix form returns the new value -alert( b++ ); // 1, postfix form returns the old value +alert( ++a ); // 2, prefix forma vraća novu vrijednost +alert( b++ ); // 1, postfix forma vraća staru vrijednost -alert( a ); // 2, incremented once -alert( b ); // 2, incremented once +alert( a ); // 2, povećana jednom +alert( b ); // 2, povećana jednom ``` From 41dd2cd5d49b498ad8ee35d83249968866f2a02f Mon Sep 17 00:00:00 2001 From: Aiyo <43038017+aiyodev@users.noreply.github.com> Date: Tue, 4 Aug 2020 12:04:34 +0200 Subject: [PATCH 06/11] Update task.md --- .../02-first-steps/08-operators/2-assignment-result/task.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/1-js/02-first-steps/08-operators/2-assignment-result/task.md b/1-js/02-first-steps/08-operators/2-assignment-result/task.md index 5345c9485..cd710e65c 100644 --- a/1-js/02-first-steps/08-operators/2-assignment-result/task.md +++ b/1-js/02-first-steps/08-operators/2-assignment-result/task.md @@ -1,10 +1,10 @@ -importance: 3 +važnost: 3 --- -# Assignment result +# Rezultat dodjele -What are the values of `a` and `x` after the code below? +Koje su vrijednosti varijabli `a` i `x` poslije koda ispod? ```js let a = 2; From f025f788243db5814f67657bde30cc2b0507afad Mon Sep 17 00:00:00 2001 From: Aiyo <43038017+aiyodev@users.noreply.github.com> Date: Tue, 4 Aug 2020 12:05:15 +0200 Subject: [PATCH 07/11] Update solution.md --- .../08-operators/2-assignment-result/solution.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/1-js/02-first-steps/08-operators/2-assignment-result/solution.md b/1-js/02-first-steps/08-operators/2-assignment-result/solution.md index e3113b4cd..7d74d7fe9 100644 --- a/1-js/02-first-steps/08-operators/2-assignment-result/solution.md +++ b/1-js/02-first-steps/08-operators/2-assignment-result/solution.md @@ -1,5 +1,5 @@ -The answer is: +Odgovor je: -- `a = 4` (multiplied by 2) -- `x = 5` (calculated as 1 + 4) +- `a = 4` (pomnoženo sa 2) +- `x = 5` (izračunato kao 1 + 4) From b8e5e641d9217c8753624e0552f2d5ac3318d71e Mon Sep 17 00:00:00 2001 From: Aiyo <43038017+aiyodev@users.noreply.github.com> Date: Tue, 4 Aug 2020 12:06:36 +0200 Subject: [PATCH 08/11] Update task.md --- .../3-primitive-conversions-questions/task.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/1-js/02-first-steps/08-operators/3-primitive-conversions-questions/task.md b/1-js/02-first-steps/08-operators/3-primitive-conversions-questions/task.md index 930c71514..6b8f4b129 100644 --- a/1-js/02-first-steps/08-operators/3-primitive-conversions-questions/task.md +++ b/1-js/02-first-steps/08-operators/3-primitive-conversions-questions/task.md @@ -1,10 +1,10 @@ -importance: 5 +važnost: 5 --- -# Type conversions +# Konverzije tipova podataka -What are results of these expressions? +Koji su rezultati ovih izraza? ```js no-beautify "" + 1 + 0 @@ -24,4 +24,4 @@ undefined + 1 " \t \n" - 2 ``` -Think well, write down and then compare with the answer. +Razmisli dobro, napiši i poredi sa odgovorom. From 3e07b8168f891e16c3eee39b0f142e6240a502ac Mon Sep 17 00:00:00 2001 From: Aiyo <43038017+aiyodev@users.noreply.github.com> Date: Tue, 4 Aug 2020 12:12:43 +0200 Subject: [PATCH 09/11] Update solution.md --- .../3-primitive-conversions-questions/solution.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/1-js/02-first-steps/08-operators/3-primitive-conversions-questions/solution.md b/1-js/02-first-steps/08-operators/3-primitive-conversions-questions/solution.md index 9a8411fbe..d7c925f28 100644 --- a/1-js/02-first-steps/08-operators/3-primitive-conversions-questions/solution.md +++ b/1-js/02-first-steps/08-operators/3-primitive-conversions-questions/solution.md @@ -17,10 +17,10 @@ undefined + 1 = NaN // (6) " \t \n" - 2 = -2 // (7) ``` -1. The addition with a string `"" + 1` converts `1` to a string: `"" + 1 = "1"`, and then we have `"1" + 0`, the same rule is applied. -2. The subtraction `-` (like most math operations) only works with numbers, it converts an empty string `""` to `0`. -3. The addition with a string appends the number `5` to the string. -4. The subtraction always converts to numbers, so it makes `" -9 "` a number `-9` (ignoring spaces around it). -5. `null` becomes `0` after the numeric conversion. -6. `undefined` becomes `NaN` after the numeric conversion. -7. Space characters, are trimmed off string start and end when a string is converted to a number. Here the whole string consists of space characters, such as `\t`, `\n` and a "regular" space between them. So, similarly to an empty string, it becomes `0`. +1. Sabiranje sa string-om `"" + 1` pretvara `1` u string: `"" + 1 = "1"`, onda imamo `"1" + 0`, isto pravilo je primijenjeno. +2. Oduzimanje `-` (kao većina matematičkih operacija) radi samo sa brojevima, uvijek pretvara prazan string `""` u `0`. +3. Sabiranje sa string-om nadodaje broj `5` na string. +4. Oduzimanje uvijek pretvara u brojeve, tako da pretvara `" -9 "` u broj `-9` (ignoriše razmake okolo). +5. `null` postaje `0` nakon numeričke konverzije. +6. `undefined` postaje `NaN` nakon numeričke konverzije. +7. Razmaci su sklonjeni sa početka i kraja string-a kada ga pretvaramo u broj. Ovdje se čitav string sastoji od razmaka, kao što su `\t`, `\n` i "obični" razmak između njih. Tako da, slično praznom string-u, postaje `0`. From a830c297b15c7a8b13e463574345491a85c97ae7 Mon Sep 17 00:00:00 2001 From: Aiyo <43038017+aiyodev@users.noreply.github.com> Date: Tue, 4 Aug 2020 12:14:33 +0200 Subject: [PATCH 10/11] Update task.md --- 1-js/02-first-steps/08-operators/4-fix-prompt/task.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/1-js/02-first-steps/08-operators/4-fix-prompt/task.md b/1-js/02-first-steps/08-operators/4-fix-prompt/task.md index b3ea4a3a3..bf0d2add0 100644 --- a/1-js/02-first-steps/08-operators/4-fix-prompt/task.md +++ b/1-js/02-first-steps/08-operators/4-fix-prompt/task.md @@ -1,14 +1,14 @@ -importance: 5 +važnost: 5 --- -# Fix the addition +# Popravi sabiranje -Here's a code that asks the user for two numbers and shows their sum. +Ovdje imamo kod koji pita korisnika za dva broja i prikazuje njihov zbir. -It works incorrectly. The output in the example below is `12` (for default prompt values). +Ne radi ispravno. Izlaz u primjeru ispod je `12` (za uobičajene prompt vrijednosti). -Why? Fix it. The result should be `3`. +Zašto? Popravi. Rezultat treba biti `3`. ```js run let a = prompt("First number?", 1); From a118be0ba9e4b356b42074bd5da7d96bfb826ea0 Mon Sep 17 00:00:00 2001 From: Aiyo <43038017+aiyodev@users.noreply.github.com> Date: Tue, 4 Aug 2020 12:17:56 +0200 Subject: [PATCH 11/11] Update solution.md --- .../08-operators/4-fix-prompt/solution.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/1-js/02-first-steps/08-operators/4-fix-prompt/solution.md b/1-js/02-first-steps/08-operators/4-fix-prompt/solution.md index 04f73fbd0..bdaa7fb59 100644 --- a/1-js/02-first-steps/08-operators/4-fix-prompt/solution.md +++ b/1-js/02-first-steps/08-operators/4-fix-prompt/solution.md @@ -1,6 +1,6 @@ -The reason is that prompt returns user input as a string. +Razlog je zato što prompt vraća unos korisnika kao string. -So variables have values `"1"` and `"2"` respectively. +Tako da varijable imaju vrijednosti `"1"` i `"2"` respketivno. ```js run let a = "1"; // prompt("First number?", 1); @@ -9,9 +9,9 @@ let b = "2"; // prompt("Second number?", 2); alert(a + b); // 12 ``` -What we should to is to convert strings to numbers before `+`. For example, using `Number()` or prepending them with `+`. +Ono šta mi trebamo uraditi jeste pretvoriti string-ove u brojeve prije `+`. Na primjer, koristeći `Number()` ili dodavajući `+` ispred njih. -For example, right before `prompt`: +Na primjer, prije `prompt`: ```js run let a = +prompt("First number?", 1); @@ -20,7 +20,7 @@ let b = +prompt("Second number?", 2); alert(a + b); // 3 ``` -Or in the `alert`: +Ili u `alert`: ```js run let a = prompt("First number?", 1); @@ -29,4 +29,4 @@ let b = prompt("Second number?", 2); alert(+a + +b); // 3 ``` -Using both unary and binary `+` in the latest code. Looks funny, doesn't it? +Koristimo i unary i binarne `+` u zadnjem kodu. Izgleda smiješno, zar ne?