diff --git a/1-js/03-code-quality/04-ninja-code/article.md b/1-js/03-code-quality/04-ninja-code/article.md index 4ed183fa..bc1283aa 100644 --- a/1-js/03-code-quality/04-ninja-code/article.md +++ b/1-js/03-code-quality/04-ninja-code/article.md @@ -45,7 +45,7 @@ The Dao hides in wordlessness. Only the Dao is well begun and well completed. ``` -Another way to code faster (and much worse!) is to use single-letter variable names everywhere. Like `a`, `b` or `c`. +Another way to code faster is to use single-letter variable names everywhere. Like `a`, `b` or `c`. A short variable disappears in the code like a real ninja in the forest. No one will be able to find it using "search" of the editor. And even if someone does, he won't be able to "decipher" what the name `a` or `b` means. @@ -83,17 +83,19 @@ While choosing a name try to use the most abstract word. Like `obj`, `data`, `va - **Name a variable by its type: `str`, `num`...** - Give them a try. A young ninja may wonder -- do such names make the code worse? Actually, yes! + Give them a try. A young initiate may wonder -- are such names really useful for a ninja? Indeed, they are! - Sure, the variable name still means something. It says what's inside the variable: a string, a number or something else. But when an outsider tries to understand the code, he'll be surprised to see that there's actually no information at all! + Sure, the variable name still means something. It says what's inside the variable: a string, a number or something else. But when an outsider tries to understand the code, he'll be surprised to see that there's actually no information at all! And will ultimately fail to alter your well-thought code. - Indeed, the value type is easy to find out by debugging. But what's the meaning of the variable? Which string/number does it store? There's just no way to figure out without a good meditation! + The value type is easy to find out by debugging. But what's the meaning of the variable? Which string/number does it store? + + There's just no way to figure out without a good meditation! - **...But what if there are no more such names?** Just add a number: `data1, item2, elem5`... ## Attention test -Only a truly attentive programmer should be able to understand the code. But how to check that? +Only a truly attentive programmer should be able to understand your code. But how to check that? **One of the ways -- use similar variable names, like `date` and `data`.** diff --git a/1-js/04-object-basics/01-object/article.md b/1-js/04-object-basics/01-object/article.md index f9e97eee..260c2457 100644 --- a/1-js/04-object-basics/01-object/article.md +++ b/1-js/04-object-basics/01-object/article.md @@ -411,8 +411,8 @@ So, "49" is an integer property name, because when it's transformed to an intege ```js run // Math.trunc is a built-in function that removes the decimal part alert( String(Math.trunc(Number("49"))) ); // "49", same, integer property -alert( String(Math.trunc(Number("+49"))) ); // "49", not same ⇒ not integer property -alert( String(Math.trunc(Number("1.2"))) ); // "1", not same ⇒ not integer property +alert( String(Math.trunc(Number("+49"))) ); // "49", not same "+49" ⇒ not integer property +alert( String(Math.trunc(Number("1.2"))) ); // "1", not same "1.2" ⇒ not integer property ``` ```` diff --git a/2-ui/3-event-details/10-onload-ondomcontentloaded/article.md b/2-ui/3-event-details/10-onload-ondomcontentloaded/article.md index 277b70ef..11305212 100644 --- a/2-ui/3-event-details/10-onload-ondomcontentloaded/article.md +++ b/2-ui/3-event-details/10-onload-ondomcontentloaded/article.md @@ -128,28 +128,24 @@ For that we should use another event -- `onbeforeunload`. ## window.onbeforeunload [#window.onbeforeunload] -If a visitor initiated leaving the page or tries to close the window, the `beforeunload` handler can ask for additional confirmation. +If a visitor initiated navigation away from the page or tries to close the window, the `beforeunload` handler asks for additional confirmation. -It needs to return the string with the question. The browser will show it. +It may return a string with the question. Historically browsers used to show it, but as of now only some of them do. That's because certain webmasters abused this event handler, to protect the visitor from potentially misleading and hackish messages. -For instance: +You can try it by running this code and then reloading the page. -```js +```js run window.onbeforeunload = function() { return "There are unsaved changes. Leave now?"; }; ``` ```online -Click on the button in `