From 239be5b99637161418355848b1d7c408a6a0b973 Mon Sep 17 00:00:00 2001 From: Otmar Onderek Date: Mon, 18 Apr 2022 22:31:29 +0200 Subject: [PATCH 01/17] 1.2.8 --- .../1-increment-order/solution.md | 10 +- .../08-operators/1-increment-order/task.md | 4 +- .../2-assignment-result/solution.md | 6 +- .../08-operators/2-assignment-result/task.md | 4 +- .../solution.md | 14 +- .../3-primitive-conversions-questions/task.md | 6 +- .../08-operators/4-fix-prompt/solution.md | 24 +- .../08-operators/4-fix-prompt/task.md | 12 +- 1-js/02-first-steps/08-operators/article.md | 379 +++++++++--------- 9 files changed, 228 insertions(+), 231 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..8b74cbb79 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: +Odpověď zní: - `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, prefixová forma vrátí novou hodnotu +alert( b++ ); // 1, postfixová forma vrátí starou hodnotu -alert( a ); // 2, incremented once -alert( b ); // 2, incremented once +alert( a ); // 2, zvýšeno jedenkrát +alert( b ); // 2, zvýšeno jedenkrát ``` 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..7ac0aeeda 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 @@ -2,9 +2,9 @@ importance: 5 --- -# The postfix and prefix forms +# Postfixová a prefixová forma -What are the final values of all variables `a`, `b`, `c` and `d` after the code below? +Jaké jsou konečné hodnoty všech proměnných `a`, `b`, `c` a `d` po provedení uvedeného kódu? ```js let a = 1, b = 1; 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..baa4d477d 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: +Odpověď zní: -- `a = 4` (multiplied by 2) -- `x = 5` (calculated as 1 + 4) +- `a = 4` (vynásobí se 2) +- `x = 5` (vypočítá se jako 1 + 4) 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..42438ec9d 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 @@ -2,9 +2,9 @@ importance: 3 --- -# Assignment result +# Výsledek přiřazení -What are the values of `a` and `x` after the code below? +Jaké jsou hodnoty proměnných `a` a `x` po provedení uvedeného kódu? ```js let a = 2; 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 dfd061cb6..ff417168e 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 @@ -16,10 +16,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. Sčítání s řetězcem `"" + 1` převede `1` na řetězec: `"" + 1 = "1"`, pak tedy budeme mít `"1" + 0` a použije se stejné pravidlo. +2. Odčítání `-` (stejně jako většina matematických operací) pracuje jen s čísly, takže převede prázdný řetězec `""` na `0`. +3. Sčítání s řetězcem připojí k řetězci číslo `5`. +4. Odčítání vždy převádí operandy na čísla, takže vyrobí z `" -9 "` číslo `-9` (mezery okolo něj se ignorují). +5. `null` se převede na číslo `0`. +6. `undefined` se převede na číslo `NaN`. +7. Když se řetězec převádí na číslo, mezerové znaky se z jeho začátku a konce odříznou. V tomto případě se celý řetězec skládá z mezerových znaků, konkrétně `\t`, `\n` a „obyčejné“ mezery mezi nimi. Stejně jako prázdný řetězec se tedy převede na `0`. 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 068420c7d..63c3c09f5 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 @@ -2,9 +2,9 @@ importance: 5 --- -# Type conversions +# Typová konverze -What are results of these expressions? +Jaké jsou výsledky následujících výrazů? ```js no-beautify "" + 1 + 0 @@ -23,4 +23,4 @@ undefined + 1 " \t \n" - 2 ``` -Think well, write down and then compare with the answer. +Dobře si to promyslete, zapište si výsledky a pak je porovnejte s odpovědí. 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 209a0702c..59c046435 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,32 +1,32 @@ -The reason is that prompt returns user input as a string. +Důvodem je, že funkce `prompt` vrací uživatelský vstup jako řetězec. -So variables have values `"1"` and `"2"` respectively. +V proměnných jsou tedy hodnoty po řadě `"1"` a `"2"`. ```js run -let a = "1"; // prompt("First number?", 1); -let b = "2"; // prompt("Second number?", 2); +let a = "1"; // prompt("První číslo?", 1); +let b = "2"; // prompt("Druhé číslo?", 2); alert(a + b); // 12 ``` -What we should do is to convert strings to numbers before `+`. For example, using `Number()` or prepending them with `+`. +To, co bychom měli udělat, je před sečtením převést řetězce na čísla. Například použít `Number()` nebo před ně uvést `+`. -For example, right before `prompt`: +Například rovnou před `prompt`: ```js run -let a = +prompt("First number?", 1); -let b = +prompt("Second number?", 2); +let a = +prompt("První číslo?", 1); +let b = +prompt("Druhé číslo?", 2); alert(a + b); // 3 ``` -Or in the `alert`: +Nebo až při volání `alert`: ```js run -let a = prompt("First number?", 1); -let b = prompt("Second number?", 2); +let a = prompt("První číslo?", 1); +let b = prompt("Druhé číslo?", 2); alert(+a + +b); // 3 ``` -Using both unary and binary `+` in the latest code. Looks funny, doesn't it? +V posledním kódu používáme současně unární i binární `+`. Vypadá to legračně, že? 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..a298b2eef 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 @@ -2,17 +2,17 @@ importance: 5 --- -# Fix the addition +# Opravte sčítání -Here's a code that asks the user for two numbers and shows their sum. +Následující kód se zeptá uživatele na dvě čísla a zobrazí jejich součet. -It works incorrectly. The output in the example below is `12` (for default prompt values). +Nefunguje však správně. Výstup v níže uvedeném příkladu (pro defaultní hodnoty v dotazech) je `12`. -Why? Fix it. The result should be `3`. +Proč? Opravte jej. Výsledek by měl být `3`. ```js run -let a = prompt("First number?", 1); -let b = prompt("Second number?", 2); +let a = prompt("První číslo?", 1); +let b = prompt("Druhé číslo?", 2); alert(a + b); // 12 ``` diff --git a/1-js/02-first-steps/08-operators/article.md b/1-js/02-first-steps/08-operators/article.md index fbf2cbf9a..314c55851 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 +# Základní operátory, matematika -We know many operators from school. They are things like addition `+`, multiplication `*`, subtraction `-`, and so on. +Mnoho operátorů známe ze školy. Jsou mezi nimi sčítání `+`, násobení `*`, odčítání `-` a podobně. -In this chapter, we’ll start with simple operators, then concentrate on JavaScript-specific aspects, not covered by school arithmetic. +V této kapitole začneme jednoduchými operátory a pak se budeme soustředit na prvky specifické pro JavaScript, které školní aritmetika nepokrývá. -## Terms: "unary", "binary", "operand" +## Pojmy: „unární“, „binární“, „operand“ -Before we move on, let's grasp some common terminology. +Než budeme pokračovat, ujasníme si určitou společnou terminologii. -- *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 to, na co se aplikují operátory. Například při násobení `5 * 2` máme dva operandy: levý operand je `5` a pravý operand je `2`. Někdy se jim místo „operandy“ říká „argumenty“. +- Operátor je *unární*, jestliže má jediný operand. Například unární negace `-`, která obrací znaménko čísla: ```js run let x = 1; @@ -17,50 +17,50 @@ Before we move on, let's grasp some common terminology. *!* x = -x; */!* - alert( x ); // -1, unary negation was applied + alert( x ); // -1, byla aplikována unární negace ``` -- An operator is *binary* if it has two operands. The same minus exists in binary form as well: +- Operátor je *binární*, jestliže má dva operandy. Stejné minus existuje i v binární podobě: ```js run no-beautify let x = 1, y = 3; - alert( y - x ); // 2, binary minus subtracts values + alert( y - x ); // 2, binární minus odečítá hodnoty ``` - 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. +Formálně mají výše uvedené příklady dva různé operátory, které mají stejný symbol: operátor negace, což je unární operátor měnící znaménko, a operátor odčítání, což je binární operátor odečítající jedno číslo od druhého. -## Maths +## Matematika -The following math operations are supported: +JavaScript podporuje následující matematické operace: -- Addition `+`, -- Subtraction `-`, -- Multiplication `*`, -- Division `/`, -- Remainder `%`, -- Exponentiation `**`. +- sčítání `+`, +- odčítání `-`, +- násobení `*`, +- dělení `/`, +- zbytek po dělení `%`, +- umocňování `**`. -The first four are straightforward, while `%` and `**` need a few words about them. +První čtyři jsou jasné, `%` a `**` potřebují trochu vysvětlení. -### Remainder % +### Zbytek po dělení % -The remainder operator `%`, despite its appearance, is not related to percents. +Operátor zbytku po dělení `%` nemá navzdory svému symbolu nic společného s procenty. -The result of `a % b` is the [remainder](https://en.wikipedia.org/wiki/Remainder) of the integer division of `a` by `b`. +Výsledkem `a % b` je [zbytek](https://cs.wikipedia.org/wiki/Zbytek_po_dělení) při celočíselném dělení čísla `a` číslem `b`. -For instance: +Příklad: ```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, zbytek po dělení 5 děleno 2 +alert( 8 % 3 ); // 2, zbytek po dělení 8 děleno 3 ``` -### Exponentiation ** +### Umocňování ** -The exponentiation operator `a ** b` raises `a` to the power of `b`. +Operátor umocňování `a ** b` umocní `a` na `b`-tou. -In school maths, we write that as ab. +Ve školní matematice to zapisujeme ab. -For instance: +Příklad: ```js run alert( 2 ** 2 ); // 2² = 4 @@ -68,72 +68,71 @@ alert( 2 ** 3 ); // 2³ = 8 alert( 2 ** 4 ); // 2⁴ = 16 ``` -Just like in maths, the exponentiation operator is defined for non-integer numbers as well. +Stejně jako v matematice je operátor umocňování definován i pro necelá čísla. -For example, a square root is an exponentiation by ½: +Například odmocnina je umocnění na ½: ```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 (umocnění na 1/2 je totéž jako druhá odmocnina) +alert( 8 ** (1/3) ); // 2 (umocnění na 1/3 je totéž jako třetí odmocnina) ``` -## String concatenation with binary + +## Spojení řetězců pomocí binárního + -Let's meet features of JavaScript operators that are beyond school arithmetics. +Přejděme nyní k vlastnostem JavaScriptu, které jsou za hranicemi školní aritmetiky. -Usually, the plus operator `+` sums numbers. - -But, if the binary `+` is applied to strings, it merges (concatenates) them: +Operátor plus `+` obvykle sčítá čísla. Pokud je však binární `+` použito na řetězce, spojí je (zřetězí): ```js -let s = "my" + "string"; -alert(s); // mystring +let s = "můj" + "řetězec"; +alert(s); // můjřetězec ``` -Note that if any of the operands is a string, then the other one is converted to a string too. +Všimněte si, že jestliže je kterýkoli z operandů řetězec, bude na řetězec převeden i druhý operand. -For example: +Příklad: ```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. +Vidíme, že nezáleží na tom, zda je řetězec první nebo druhý operand. -Here's a more complex example: +Složitější příklad: ```js run -alert(2 + 2 + '1' ); // "41" and not "221" +alert(2 + 2 + '1' ); // "41", 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'`. +Tady operátory fungují jeden za druhým. První `+` sečte dvě čísla, takže vrátí `4`, pak druhé `+` k němu přidá řetězec `1`, takže je to jako `4 + '1' = 41`. ```js run -alert('1' + 2 + 2); // "122" and not "14" +alert('1' + 2 + 2); // "122" a ne "14" ``` -Here, the first operand is a string, the compiler treats the other two operands as strings too. The `2` gets concatenated to `'1'`, so it's like `'1' + 2 = "12"` and `"12" + 2 = "122"`. -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. +První operand je zde řetězec, takže kompilátor zachází i s ostatními dvěma operandy jako s řetězci. `2` se zřetězí s `'1'`, takže to bude jako `'1' + 2 = "12"` a `"12" + 2 = "122"`. + +Binární `+` je jediný operátor, který takovýmto způsobem podporuje řetězce. Ostatní aritmetické operátory fungují jen s čísly a své operandy převádějí vždy na čísla. -Here's the demo for subtraction and division: +Ukázka odčítání a dělení: ```js run -alert( 6 - '2' ); // 4, converts '2' to a number -alert( '6' / '2' ); // 3, converts both operands to numbers +alert( 6 - '2' ); // 4, převede '2' na číslo +alert( '6' / '2' ); // 3, převede oba operandy na čísla ``` -## Numeric conversion, unary + +## Konverze na číslo a unární + -The plus `+` exists in two forms: the binary form that we used above and the unary form. +Plus `+` existuje ve dvou podobách: binární, kterou jsme používali výše, a unární. -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. +Unární plus, jinými slovy operátor `+` aplikovaný na jedinou hodnotu, neprovádí s čísly nic. Jestliže však operand není číslo, unární plus jej převede na číslo. -For example: +Příklad: ```js run -// No effect on numbers +// Žádný efekt na čísla let x = 1; alert( +x ); // 1 @@ -141,77 +140,77 @@ let y = -2; alert( +y ); // -2 *!* -// Converts non-numbers +// Převádí hodnoty, které nejsou čísla alert( +true ); // 1 alert( +"" ); // 0 */!* ``` -It actually does the same thing as `Number(...)`, but is shorter. +Dělá tedy ve skutečnosti totéž jako `Number(...)`, ale je kratší. -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? +Potřeba převádět řetězce na čísla se objevuje velmi často. Například jestliže načítáme hodnoty z polí HTML formulářů, jsou to obvykle řetězce. Co když je chceme sečíst? -The binary plus would add them as strings: +Binární plus by je spojilo jako řetězce: ```js run -let apples = "2"; -let oranges = "3"; +let jablka = "2"; +let pomeranče = "3"; -alert( apples + oranges ); // "23", the binary plus concatenates strings +alert( jablka + pomeranče ); // "23", binární plus spojuje řetězce ``` -If we want to treat them as numbers, we need to convert and then sum them: +Pokud s nimi chceme zacházet jako s čísly, musíme je napřed konvertovat a teprve pak sečíst: ```js run -let apples = "2"; -let oranges = "3"; +let jablka = "2"; +let pomeranče = "3"; *!* -// both values converted to numbers before the binary plus -alert( +apples + +oranges ); // 5 +// obě hodnoty převedeme na čísla před binárním plus +alert( +jablka + +pomeranče ); // 5 */!* -// the longer variant -// alert( Number(apples) + Number(oranges) ); // 5 +// delší varianta +// alert( Number(jablka) + Number(pomeranče) ); // 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. +Z pohledu matematika může přemíra plusů vypadat podivně, ale z pohledu programátora na tom nic zvláštního není: nejprve se aplikují unární plusy, které převedou řetězce na čísla, a pak je binární plus sečte. -Why are unary pluses applied to values before the binary ones? As we're going to see, that's because of their *higher precedence*. +Proč se unární plusy aplikují na hodnoty dříve než binární? Jak uvidíme, je to důsledkem jejich *vyšší priority*. -## Operator precedence +## Priorita operátorů -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. +Obsahuje-li výraz více než jeden operátor, je pořadí jejich výkonu definováno jejich *prioritou*, nebo jinými slovy standardním pořadím operátorů. -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. +Ze školy jistě všichni víme, že ve výrazu `1 + 2 * 2` by násobení mělo být vyhodnoceno před sčítáním. To je přesně otázkou priority. Říkáme, že násobení má *vyšší prioritu* než sčítání. -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`. +Závorky mají přednost před veškerou prioritou, takže nejsme-li spokojeni se standardním pořadím, můžeme je s jejich pomocí změnit. Například zapíšeme `(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. +JavaScript obsahuje mnoho operátorů. Každému z nich odpovídá hodnota jeho priority. Dříve se vykoná ten, jehož priorita je vyšší. Je-li priorita více operátorů stejná, vykonávají se v pořadí zleva doprava. -Here's an extract from the [precedence table](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence) (you don't need to remember this, but note that unary operators are higher than corresponding binary ones): +Následuje výtažek z [tabulky priorit](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence) (nemusíte si ji celou pamatovat, ale všimněte si, že unární operátory mají vyšší prioritu než odpovídající binární): -| Precedence | Name | Sign | -|------------|------|------| +| Priorita | Název | Znak | +|----------|-------|------| | ... | ... | ... | -| 15 | unary plus | `+` | -| 15 | unary negation | `-` | -| 14 | exponentiation | `**` | -| 13 | multiplication | `*` | -| 13 | division | `/` | -| 12 | addition | `+` | -| 12 | subtraction | `-` | +| 15 | unární plus | `+` | +| 15 | unární negace | `-` | +| 14 | umocňování | `**` | +| 13 | násobení | `*` | +| 13 | dělení | `/` | +| 12 | sčítání | `+` | +| 12 | odčítání | `-` | | ... | ... | ... | -| 2 | assignment | `=` | +| 2 | přiřazení | `=` | | ... | ... | ... | -As we can see, the "unary plus" has a priority of `15` which is higher than the `12` of "addition" (binary plus). That's why, in the expression `"+apples + +oranges"`, unary pluses work before the addition. +Jak vidíme, „unární plus“ má prioritu `15`, která je vyšší než priorita `12` „sčítání“ (binární plus). To je důvod, proč se ve výrazu `"+jablka + +pomeranče"` unární plusy vyhodnotí před sčítáním. -## Assignment +## Přiřazení -Let's note that an assignment `=` is also an operator. It is listed in the precedence table with the very low priority of `2`. +Všimněte si, že přiřazení `=` je také operátor. V tabulce priorit je uveden s velmi nízkou prioritou `2`. -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`. +To je důvod, proč při přiřazení proměnné, např. `x = 2 * 2 + 1`, se nejprve provedou výpočty a až potom se vyhodnotí `=`, které uloží výsledek do `x`. ```js let x = 2 * 2 + 1; @@ -219,15 +218,15 @@ let x = 2 * 2 + 1; alert( x ); // 5 ``` -### Assignment = returns a value +### Přiřazení = vrátí hodnotu -The fact of `=` being an operator, not a "magical" language construct has an interesting implication. +Skutečnost, že `=` je operátor a ne nějaký „magický“ jazykový konstrukt, má zajímavý důsledek. -All operators in JavaScript return a value. That's obvious for `+` and `-`, but also true for `=`. +Všechny operátory v JavaScriptu vracejí nějakou hodnotu. Pro `+` a `-` je to samozřejmé, ale platí to i pro `=`. -The call `x = value` writes the `value` into `x` *and then returns it*. +Volání `x = hodnota` zapíše hodnotu `hodnota` do `x` *a pak ji vrátí*. -Here's a demo that uses an assignment as part of a more complex expression: +Následuje ukázka, v níž je přiřazení využito jako součást složitějšího výrazu: ```js run let a = 1; @@ -241,15 +240,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. +V uvedeném příkladu je výsledkem výrazu `(a = b + 1)` hodnota, která je přiřazena do `a` (což je `3`). Ta se pak použije pro další výpočty. -Funny code, isn't it? We should understand how it works, because sometimes we see it in JavaScript libraries. +Legrační kód, že? Měli bychom porozumět, jak funguje, protože v knihovnách JavaScriptu bývá občas k vidění. -Although, please don't write the code like that. Such tricks definitely don't make code clearer or readable. +Přesto vás prosíme, abyste takový kód nepsali. Takové triky zcela jistě nepřispívají k jeho jasnosti a čitelnosti. -### Chaining assignments +### Zřetězení přiřazení -Another interesting feature is the ability to chain assignments: +Další zajímavá vlastnost je možnost zřetězit přiřazení za sebou: ```js run let a, b, c; @@ -263,22 +262,22 @@ 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. +Zřetězená přiřazení se vyhodnocují zprava doleva. Nejprve se vyhodnotí výraz `2 + 2` nejvíce vpravo a jeho hodnota se pak přiřadí do proměnných vlevo: `c`, `b` a `a`. Nakonec tedy budou mít všechny proměnné stejnou hodnotu. -Once again, for the purposes of readability it's better to split such code into few lines: +Opět je pro účely čitelnosti lepší rozdělit takový kód do více řádků: ```js c = 2 + 2; b = c; a = c; ``` -That's easier to read, especially when eye-scanning the code fast. +Snadněji se to čte, zejména když kód rychle projíždíte očima. -## Modify-in-place +## Modifikace na místě -We often need to apply an operator to a variable and store the new result in that same variable. +Často potřebujeme aplikovat operátor na nějakou proměnnou a uložit nový výsledek do této proměnné. -For example: +Příklad: ```js let n = 2; @@ -286,194 +285,192 @@ n = n + 5; n = n * 2; ``` -This notation can be shortened using the operators `+=` and `*=`: +Tento zápis lze zkrátit pomocí operátorů `+=` a `*=`: ```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; // nyní n = 7 (totéž jako n = n + 5) +n *= 2; // nyní n = 14 (totéž jako n = n * 2) alert( n ); // 14 ``` -Short "modify-and-assign" operators exist for all arithmetical and bitwise operators: `/=`, `-=`, etc. +Takové „modifikační“ operátory existují pro všechny aritmetické a bitové operace: `/=`, `-=`, apod. -Such operators have the same precedence as a normal assignment, so they run after most other calculations: +Tyto operátory mají stejnou prioritu jako běžné přiřazení, takže se provedou až po většině ostatních výpočtů: ```js run let n = 2; n *= 3 + 5; -alert( n ); // 16 (right part evaluated first, same as n *= 8) +alert( n ); // 16 (napřed se provede část vpravo, totéž jako n *= 8) ``` -## Increment/decrement +## Inkrementace a dekrementace -Increasing or decreasing a number by one is among the most common numerical operations. - -So, there are special operators for it: +Jednou z nejběžnějších číselných operací je zvýšení nebo snížení čísla o 1 (inkrementace, dekrementace). Proto pro ně existují speciální operátory: -- **Increment** `++` increases a variable by 1: +- **Inkrementace** `++` zvýší proměnnou o 1: ```js run no-beautify - let counter = 2; - counter++; // works the same as counter = counter + 1, but is shorter - alert( counter ); // 3 + let čítač = 2; + čítač++; // funguje stejně jako čítač = čítač + 1, ale je to kratší + alert( čítač ); // 3 ``` -- **Decrement** `--` decreases a variable by 1: +- **Dekrementace** `--` sníží proměnnou o 1: ```js run no-beautify - let counter = 2; - counter--; // works the same as counter = counter - 1, but is shorter - alert( counter ); // 1 + let čítač = 2; + čítač--; // funguje stejně jako čítač = čítač - 1, ale je to kratší + alert( čítač ); // 1 ``` ```warn -Increment/decrement can only be applied to variables. Trying to use it on a value like `5++` will give an error. +Inkrementaci a dekrementaci lze aplikovat pouze na proměnné. Pokus použít ji na hodnotu, např. `5++`, vyvolá chybu. ``` -The operators `++` and `--` can be placed either before or after a variable. +Operátory `++` a `--` lze umístit před i za proměnnou. -- 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`. +- Je-li operátor umístěn za proměnnou, nazývá se to „postfixová forma“: `čítač++`. +- „Prefixová forma“ je umístění operátoru před proměnnou: `++čítač`. -Both of these statements do the same thing: increase `counter` by `1`. +Oba tyto příkazy vykonají totéž: zvýší `čítač` o `1`. -Is there any difference? Yes, but we can only see it if we use the returned value of `++/--`. +Je v nich tedy nějaký rozdíl? Ano, ale uvidíme ho jen tehdy, když použijeme hodnotu, kterou operátor `++/--` vrátí. -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). +Ujasněme si to. Jak víme, všechny operátory vracejí nějakou hodnotu. Inkrementace a dekrementace nejsou výjimkou. Prefixová forma vrací novou hodnotu, zatímco postfixová forma vrací starou hodnotu (tu před zvýšením nebo snížením). -To see the difference, here's an example: +Abychom viděli rozdíl, uvedeme příklad: ```js run -let counter = 1; -let a = ++counter; // (*) +let čítač = 1; +let a = ++čítač; // (*) alert(a); // *!*2*/!* ``` -In the line `(*)`, the *prefix* form `++counter` increments `counter` and returns the new value, `2`. So, the `alert` shows `2`. +Na řádku `(*)` *prefixová* forma `++čítač` zvýšila `čítač` a vrátila novou hodnotu, `2`. Proto `alert` zobrazila `2`. -Now, let's use the postfix form: +Nyní použijeme postfixovou formu: ```js run -let counter = 1; -let a = counter++; // (*) changed ++counter to counter++ +let čítač = 1; +let a = čítač++; // (*) změnili jsme ++čítač na čítač++ 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 řádku `(*)` *postfixová* forma `čítač++` rovněž zvýšila `čítač`, ale vrátila *starou* hodnotu (tu před zvýšením). Proto `alert` zobrazila `1`. -To summarize: +Shrneme to: -- If the result of increment/decrement is not used, there is no difference in which form to use: +- Pokud výsledek zvýšení nebo snížení nepoužijeme, není rozdíl v tom, kterou formu použijeme: ```js run - let counter = 0; - counter++; - ++counter; - alert( counter ); // 2, the lines above did the same + let čítač = 0; + čítač++; + ++čítač; + alert( čítač ); // 2, oba výše uvedené řádky dělají totéž ``` -- If we'd like to increase a value *and* immediately use the result of the operator, we need the prefix form: +- Pokud chceme zvýšit hodnotu *a* výsledek operátoru ihned použít, potřebujeme prefixovou formu: ```js run - let counter = 0; - alert( ++counter ); // 1 + let čítač = 0; + alert( ++čítač ); // 1 ``` -- If we'd like to increment a value but use its previous value, we need the postfix form: +- Pokud chceme zvýšit hodnotu, ale použít předchozí hodnotu, potřebujeme postfixovou formu: ```js run - let counter = 0; - alert( counter++ ); // 0 + let čítač = 0; + alert( čítač++ ); // 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="Inkrementace a dekrementace mezi jinými operátory" +Operátory `++/--` je možné použít i uvnitř výrazů. Jejich priorita je vyšší než priorita většiny ostatních aritmetických operací. -For instance: +Příklad: ```js run -let counter = 1; -alert( 2 * ++counter ); // 4 +let čítač = 1; +alert( 2 * ++čítač ); // 4 ``` -Compare with: +Porovnejte si to s: ```js run -let counter = 1; -alert( 2 * counter++ ); // 2, because counter++ returns the "old" value +let čítač = 1; +alert( 2 * čítač++ ); // 2, protože čítač++ vrací „starou“ hodnotu ``` -Though technically okay, such notation usually makes code less readable. One line does multiple things -- not good. +Ačkoli je to technicky v pořádku, takový zápis obvykle snižuje čitelnost kódu. Jeden řádek provádí více věcí, a to není dobré. -While reading code, a fast "vertical" eye-scan can easily miss something like `counter++` and it won't be obvious that the variable increased. +Když čteme kód, při rychlém „svislém“ projíždění očima můžeme snadno přehlédnout něco jako `čítač++` a nevšimneme si, že se proměnná zvýšila. -We advise a style of "one line -- one action": +Doporučujeme psát stylem „jeden řádek -- jedna akce“: ```js run -let counter = 1; -alert( 2 * counter ); -counter++; +let čítač = 1; +alert( 2 * čítač ); +čítač++; ``` ```` -## Bitwise operators +## Bitové operátory -Bitwise operators treat arguments as 32-bit integer numbers and work on the level of their binary representation. +Bitové operátory zacházejí s argumenty jako s 32-bitovými celými čísly a pracují na úrovni jejich binární reprezentace. -These operators are not JavaScript-specific. They are supported in most programming languages. +Tyto operátory nejsou specifické pro JavaScript. Podporuje je většina programovacích jazyků. -The list of operators: +Seznam operátorů: - AND ( `&` ) - OR ( `|` ) - XOR ( `^` ) - NOT ( `~` ) -- LEFT SHIFT ( `<<` ) -- RIGHT SHIFT ( `>>` ) -- ZERO-FILL RIGHT SHIFT ( `>>>` ) +- LEFT SHIFT (posun doleva) ( `<<` ) +- RIGHT SHIFT (posun doprava) ( `>>` ) +- ZERO-FILL RIGHT SHIFT (posun doprava s doplněním nul) ( `>>>` ) -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-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#bitwise_operators) chapter on MDN when a need arises. +Tyto operátory se používají jen velmi zřídka, když potřebujeme pracovat s čísly na naprosto nejnižší (bitové) úrovni. Nebudeme je v dohledné době potřebovat, jelikož při vývoji webů se využívají jen málokdy, ale jsou užitečné v některých speciálních oblastech, například v kryptografii. Až je budete potřebovat, můžete si o nich přečíst [článek](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Bitwise) na MDN. -## Comma +## Čárka -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. +Operátor čárky `,` je jeden z nejvzácnějších a nejneobvyklejších operátorů. Někdy se používá k psaní kratšího kódu, takže jej potřebujeme znát, abychom pochopili, o co tady jde. -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. +Operátor čárky nám umožňuje vyhodnotit několik výrazů za sebou, oddělených čárkou `,`. Vyhodnotí se každý z nich, ale vrátí se jen výsledek posledního. -For example: +Příklad: ```js run *!* let a = (1 + 2, 3 + 4); */!* -alert( a ); // 7 (the result of 3 + 4) +alert( a ); // 7 (výsledek 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. +Zde se napřed vyhodnotí první výraz `1 + 2` a jeho výsledek se zahodí. Pak se vyhodnotí `3 + 4` a jeho výsledek je vrácen. -```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="Čárka má velmi nízkou prioritu" +Všimněte si, že operátor čárky má velmi nízkou prioritu, dokonce nižší než `=`, takže závorky jsou ve výše uvedeném příkladu nezbytné. -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 nich: `a = 1 + 2, 3 + 4`, jako první by se vyhodnotilo `+`, které by sečetlo čísla do `a = 3, 7`, pak by operátor přiřazení `=` přiřadil `a = 3` a zbytek by se ignoroval. Bylo by to jako `(a = 1 + 2), 3 + 4`. ``` -Why do we need an operator that throws away everything except the last expression? +K čemu potřebujeme operátor, který zahodí všechno kromě posledního výrazu? -Sometimes, people use it in more complex constructs to put several actions in one line. +Někdy jej lidé používají ve složitějších konstrukcích, aby umístili několik akcí na jeden řádek. -For example: +Příklad: ```js -// three operations in one line +// tři operace na jednom řádku 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. +Takové triky se používají v mnoha rámcích JavaScriptu, a proto se o nich zmiňujeme. Obvykle však zrovna nezlepšují čitelnost kódu, a proto byste si jejich používání měli dobře rozmyslet. From 08106cb57c57bf16d8dd3b3e1dbe4058b993b0dd Mon Sep 17 00:00:00 2001 From: otmon76 <66325539+otmon76@users.noreply.github.com> Date: Tue, 17 May 2022 19:08:06 +0200 Subject: [PATCH 02/17] Update 1-js/02-first-steps/08-operators/1-increment-order/solution.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daniel Pomajbík <60559058+danipoma@users.noreply.github.com> --- 1-js/02-first-steps/08-operators/1-increment-order/solution.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 8b74cbb79..616f15daa 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 @@ -9,7 +9,7 @@ Odpověď zní: ```js run no-beautify let a = 1, b = 1; -alert( ++a ); // 2, prefixová forma vrátí novou hodnotu +alert( ++a ); // 2, prefixová notace vrátí novou hodnotu alert( b++ ); // 1, postfixová forma vrátí starou hodnotu alert( a ); // 2, zvýšeno jedenkrát From 81d715aff640df12ab5ddcb69bde28179f3c0453 Mon Sep 17 00:00:00 2001 From: otmon76 <66325539+otmon76@users.noreply.github.com> Date: Tue, 17 May 2022 19:08:16 +0200 Subject: [PATCH 03/17] Update 1-js/02-first-steps/08-operators/1-increment-order/solution.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daniel Pomajbík <60559058+danipoma@users.noreply.github.com> --- 1-js/02-first-steps/08-operators/1-increment-order/solution.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 616f15daa..908de2919 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 @@ -10,7 +10,7 @@ Odpověď zní: let a = 1, b = 1; alert( ++a ); // 2, prefixová notace vrátí novou hodnotu -alert( b++ ); // 1, postfixová forma vrátí starou hodnotu +alert( b++ ); // 1, postfixová notace vrátí starou hodnotu alert( a ); // 2, zvýšeno jedenkrát alert( b ); // 2, zvýšeno jedenkrát From abf3900a09c7c23351e59c594e21e62b747ef704 Mon Sep 17 00:00:00 2001 From: otmon76 <66325539+otmon76@users.noreply.github.com> Date: Tue, 17 May 2022 19:08:22 +0200 Subject: [PATCH 04/17] Update 1-js/02-first-steps/08-operators/1-increment-order/task.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daniel Pomajbík <60559058+danipoma@users.noreply.github.com> --- 1-js/02-first-steps/08-operators/1-increment-order/task.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 7ac0aeeda..aebe84b1a 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 @@ -2,7 +2,7 @@ importance: 5 --- -# Postfixová a prefixová forma +# Postfixová a prefixová notace Jaké jsou konečné hodnoty všech proměnných `a`, `b`, `c` a `d` po provedení uvedeného kódu? From 257132592e226bcc271a0a0881f3569a0c6cc9c5 Mon Sep 17 00:00:00 2001 From: otmon76 <66325539+otmon76@users.noreply.github.com> Date: Tue, 17 May 2022 19:08:30 +0200 Subject: [PATCH 05/17] Update 1-js/02-first-steps/08-operators/article.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daniel Pomajbík <60559058+danipoma@users.noreply.github.com> --- 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 314c55851..e281a825f 100644 --- a/1-js/02-first-steps/08-operators/article.md +++ b/1-js/02-first-steps/08-operators/article.md @@ -6,7 +6,7 @@ V této kapitole začneme jednoduchými operátory a pak se budeme soustředit n ## Pojmy: „unární“, „binární“, „operand“ -Než budeme pokračovat, ujasníme si určitou společnou terminologii. +Než budeme pokračovat, ujasníme si základní terminologii. - *Operand* je to, na co se aplikují operátory. Například při násobení `5 * 2` máme dva operandy: levý operand je `5` a pravý operand je `2`. Někdy se jim místo „operandy“ říká „argumenty“. - Operátor je *unární*, jestliže má jediný operand. Například unární negace `-`, která obrací znaménko čísla: From 5b7a89b48d053a7a376aa78bc7feb7868d48792d Mon Sep 17 00:00:00 2001 From: otmon76 <66325539+otmon76@users.noreply.github.com> Date: Tue, 17 May 2022 19:08:36 +0200 Subject: [PATCH 06/17] Update 1-js/02-first-steps/08-operators/article.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daniel Pomajbík <60559058+danipoma@users.noreply.github.com> --- 1-js/02-first-steps/08-operators/article.md | 4 +++- 1 file changed, 3 insertions(+), 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 e281a825f..7fdb125b1 100644 --- a/1-js/02-first-steps/08-operators/article.md +++ b/1-js/02-first-steps/08-operators/article.md @@ -82,7 +82,9 @@ alert( 8 ** (1/3) ); // 2 (umocnění na 1/3 je totéž jako třetí odmocnina) Přejděme nyní k vlastnostem JavaScriptu, které jsou za hranicemi školní aritmetiky. -Operátor plus `+` obvykle sčítá čísla. Pokud je však binární `+` použito na řetězce, spojí je (zřetězí): +Operátor plus `+` obvykle sčítá čísla. + +Pokud je však binární `+` použito na řetězce, spojí je (zřetězí): ```js let s = "můj" + "řetězec"; From eb3dc1b9efa735695ac2e7e24b54160324067987 Mon Sep 17 00:00:00 2001 From: otmon76 <66325539+otmon76@users.noreply.github.com> Date: Tue, 17 May 2022 19:08:45 +0200 Subject: [PATCH 07/17] Update 1-js/02-first-steps/08-operators/article.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daniel Pomajbík <60559058+danipoma@users.noreply.github.com> --- 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 7fdb125b1..791b4e8ca 100644 --- a/1-js/02-first-steps/08-operators/article.md +++ b/1-js/02-first-steps/08-operators/article.md @@ -356,7 +356,7 @@ alert(a); // *!*2*/!* Na řádku `(*)` *prefixová* forma `++čítač` zvýšila `čítač` a vrátila novou hodnotu, `2`. Proto `alert` zobrazila `2`. -Nyní použijeme postfixovou formu: +Nyní použijeme postfixovou notaci: ```js run let čítač = 1; From 53ff266e55e188cac5e3f83b075e14414f2f37eb Mon Sep 17 00:00:00 2001 From: otmon76 <66325539+otmon76@users.noreply.github.com> Date: Tue, 17 May 2022 19:09:57 +0200 Subject: [PATCH 08/17] Update 1-js/02-first-steps/08-operators/article.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daniel Pomajbík <60559058+danipoma@users.noreply.github.com> --- 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 791b4e8ca..a88a19bbf 100644 --- a/1-js/02-first-steps/08-operators/article.md +++ b/1-js/02-first-steps/08-operators/article.md @@ -365,7 +365,7 @@ let a = čítač++; // (*) změnili jsme ++čítač na čítač++ alert(a); // *!*1*/!* ``` -Na řádku `(*)` *postfixová* forma `čítač++` rovněž zvýšila `čítač`, ale vrátila *starou* hodnotu (tu před zvýšením). Proto `alert` zobrazila `1`. +Na řádku `(*)` *postfixová* notace `čítač++` rovněž zvýšila `čítač`, ale vrátila *starou* hodnotu (tu před zvýšením). Proto `alert` zobrazil `1`. Shrneme to: From 58f4a2570c54f3c359377b4ea178c6602d6cc557 Mon Sep 17 00:00:00 2001 From: otmon76 <66325539+otmon76@users.noreply.github.com> Date: Tue, 17 May 2022 19:10:04 +0200 Subject: [PATCH 09/17] Update 1-js/02-first-steps/08-operators/article.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daniel Pomajbík <60559058+danipoma@users.noreply.github.com> --- 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 a88a19bbf..d36636544 100644 --- a/1-js/02-first-steps/08-operators/article.md +++ b/1-js/02-first-steps/08-operators/article.md @@ -383,7 +383,7 @@ Shrneme to: let čítač = 0; alert( ++čítač ); // 1 ``` -- Pokud chceme zvýšit hodnotu, ale použít předchozí hodnotu, potřebujeme postfixovou formu: +- Pokud chceme zvýšit hodnotu, ale použít předchozí hodnotu, potřebujeme postfixovou notaci: ```js run let čítač = 0; From ef0ce0990f6db887325a3346271d60acccb51227 Mon Sep 17 00:00:00 2001 From: otmon76 <66325539+otmon76@users.noreply.github.com> Date: Tue, 17 May 2022 19:10:57 +0200 Subject: [PATCH 10/17] Update 1-js/02-first-steps/08-operators/article.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daniel Pomajbík <60559058+danipoma@users.noreply.github.com> --- 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 d36636544..b9f1bc0ca 100644 --- a/1-js/02-first-steps/08-operators/article.md +++ b/1-js/02-first-steps/08-operators/article.md @@ -369,7 +369,7 @@ Na řádku `(*)` *postfixová* notace `čítač++` rovněž zvýšila `čítač` Shrneme to: -- Pokud výsledek zvýšení nebo snížení nepoužijeme, není rozdíl v tom, kterou formu použijeme: +- Pokud výsledek zvýšení nebo snížení nepoužijeme, není rozdíl v tom, kterou notaci použijeme: ```js run let čítač = 0; From 4dde2aaeaa086b2d66a4aa55c4d12ef9d457a739 Mon Sep 17 00:00:00 2001 From: otmon76 <66325539+otmon76@users.noreply.github.com> Date: Tue, 17 May 2022 19:11:04 +0200 Subject: [PATCH 11/17] Update 1-js/02-first-steps/08-operators/article.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daniel Pomajbík <60559058+danipoma@users.noreply.github.com> --- 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 b9f1bc0ca..573110191 100644 --- a/1-js/02-first-steps/08-operators/article.md +++ b/1-js/02-first-steps/08-operators/article.md @@ -377,7 +377,7 @@ Shrneme to: ++čítač; alert( čítač ); // 2, oba výše uvedené řádky dělají totéž ``` -- Pokud chceme zvýšit hodnotu *a* výsledek operátoru ihned použít, potřebujeme prefixovou formu: +- Pokud chceme zvýšit hodnotu *a* výsledek operátoru ihned použít, potřebujeme prefixovou notaci: ```js run let čítač = 0; From 73d05c69fc6e2ea30af092b137eb8086848fe026 Mon Sep 17 00:00:00 2001 From: otmon76 <66325539+otmon76@users.noreply.github.com> Date: Tue, 17 May 2022 19:11:19 +0200 Subject: [PATCH 12/17] Update 1-js/02-first-steps/08-operators/article.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daniel Pomajbík <60559058+danipoma@users.noreply.github.com> --- 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 573110191..6e745f096 100644 --- a/1-js/02-first-steps/08-operators/article.md +++ b/1-js/02-first-steps/08-operators/article.md @@ -297,7 +297,7 @@ n *= 2; // nyní n = 14 (totéž jako n = n * 2) alert( n ); // 14 ``` -Takové „modifikační“ operátory existují pro všechny aritmetické a bitové operace: `/=`, `-=`, apod. +Takové „modifikační“ operátory existují pro všechny aritmetické a bitové operátory: `/=`, `-=`, apod. Tyto operátory mají stejnou prioritu jako běžné přiřazení, takže se provedou až po většině ostatních výpočtů: From 5a7d24a9ec14230f474c7199ff95d14dbaef74eb Mon Sep 17 00:00:00 2001 From: otmon76 <66325539+otmon76@users.noreply.github.com> Date: Tue, 17 May 2022 19:11:35 +0200 Subject: [PATCH 13/17] Update 1-js/02-first-steps/08-operators/article.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daniel Pomajbík <60559058+danipoma@users.noreply.github.com> --- 1-js/02-first-steps/08-operators/article.md | 4 +++- 1 file changed, 3 insertions(+), 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 6e745f096..778db3312 100644 --- a/1-js/02-first-steps/08-operators/article.md +++ b/1-js/02-first-steps/08-operators/article.md @@ -313,7 +313,9 @@ alert( n ); // 16 (napřed se provede část vpravo, totéž jako n *= 8) -Jednou z nejběžnějších číselných operací je zvýšení nebo snížení čísla o 1 (inkrementace, dekrementace). Proto pro ně existují speciální operátory: +Jednou z nejběžnějších číselných operací je zvýšení nebo snížení čísla o 1 (inkrementace, dekrementace). + +Proto pro ně existují speciální operátory: - **Inkrementace** `++` zvýší proměnnou o 1: From 477e8de5072dd13132214485504af3a96cb49d6e Mon Sep 17 00:00:00 2001 From: otmon76 <66325539+otmon76@users.noreply.github.com> Date: Tue, 17 May 2022 19:11:44 +0200 Subject: [PATCH 14/17] Update 1-js/02-first-steps/08-operators/article.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daniel Pomajbík <60559058+danipoma@users.noreply.github.com> --- 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 778db3312..3af81e22e 100644 --- a/1-js/02-first-steps/08-operators/article.md +++ b/1-js/02-first-steps/08-operators/article.md @@ -338,7 +338,7 @@ Inkrementaci a dekrementaci lze aplikovat pouze na proměnné. Pokus použít ji Operátory `++` a `--` lze umístit před i za proměnnou. -- Je-li operátor umístěn za proměnnou, nazývá se to „postfixová forma“: `čítač++`. +- Je-li operátor umístěn za proměnnou, nazývá se to „postfixová notace“: `čítač++`. - „Prefixová forma“ je umístění operátoru před proměnnou: `++čítač`. Oba tyto příkazy vykonají totéž: zvýší `čítač` o `1`. From cdf1bbfa597e3a1bac7c5a4153a0a6f3eae38671 Mon Sep 17 00:00:00 2001 From: otmon76 <66325539+otmon76@users.noreply.github.com> Date: Tue, 17 May 2022 19:11:59 +0200 Subject: [PATCH 15/17] Update 1-js/02-first-steps/08-operators/article.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daniel Pomajbík <60559058+danipoma@users.noreply.github.com> --- 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 3af81e22e..02ca8c8bf 100644 --- a/1-js/02-first-steps/08-operators/article.md +++ b/1-js/02-first-steps/08-operators/article.md @@ -339,7 +339,7 @@ Inkrementaci a dekrementaci lze aplikovat pouze na proměnné. Pokus použít ji Operátory `++` a `--` lze umístit před i za proměnnou. - Je-li operátor umístěn za proměnnou, nazývá se to „postfixová notace“: `čítač++`. -- „Prefixová forma“ je umístění operátoru před proměnnou: `++čítač`. +- „Prefixová notace“ je umístění operátoru před proměnnou: `++čítač`. Oba tyto příkazy vykonají totéž: zvýší `čítač` o `1`. From 459de0182005a988faa5f318a6e2fccd3c164dce Mon Sep 17 00:00:00 2001 From: otmon76 <66325539+otmon76@users.noreply.github.com> Date: Tue, 17 May 2022 19:12:18 +0200 Subject: [PATCH 16/17] Update 1-js/02-first-steps/08-operators/article.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daniel Pomajbík <60559058+danipoma@users.noreply.github.com> --- 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 02ca8c8bf..b8adcffee 100644 --- a/1-js/02-first-steps/08-operators/article.md +++ b/1-js/02-first-steps/08-operators/article.md @@ -345,7 +345,7 @@ Oba tyto příkazy vykonají totéž: zvýší `čítač` o `1`. Je v nich tedy nějaký rozdíl? Ano, ale uvidíme ho jen tehdy, když použijeme hodnotu, kterou operátor `++/--` vrátí. -Ujasněme si to. Jak víme, všechny operátory vracejí nějakou hodnotu. Inkrementace a dekrementace nejsou výjimkou. Prefixová forma vrací novou hodnotu, zatímco postfixová forma vrací starou hodnotu (tu před zvýšením nebo snížením). +Ujasněme si to. Jak víme, všechny operátory vracejí nějakou hodnotu. Inkrementace a dekrementace nejsou výjimkou. Prefixová notace vrací novou hodnotu, zatímco postfixová notace vrací starou hodnotu (tu před zvýšením nebo snížením). Abychom viděli rozdíl, uvedeme příklad: From 3fcabd4e0e162719352adac729273f7756610a03 Mon Sep 17 00:00:00 2001 From: otmon76 <66325539+otmon76@users.noreply.github.com> Date: Tue, 17 May 2022 19:12:29 +0200 Subject: [PATCH 17/17] Update 1-js/02-first-steps/08-operators/article.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daniel Pomajbík <60559058+danipoma@users.noreply.github.com> --- 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 b8adcffee..1ce09db33 100644 --- a/1-js/02-first-steps/08-operators/article.md +++ b/1-js/02-first-steps/08-operators/article.md @@ -356,7 +356,7 @@ let a = ++čítač; // (*) alert(a); // *!*2*/!* ``` -Na řádku `(*)` *prefixová* forma `++čítač` zvýšila `čítač` a vrátila novou hodnotu, `2`. Proto `alert` zobrazila `2`. +Na řádku `(*)` *prefixová* notace `++čítač` zvýšila `čítač` a vrátila novou hodnotu, `2`. Proto `alert` zobrazila `2`. Nyní použijeme postfixovou notaci: