diff --git a/1-js/02-first-steps/01-hello-world/article.md b/1-js/02-first-steps/01-hello-world/article.md index 8de9df96b7..5126f4bc44 100644 --- a/1-js/02-first-steps/01-hello-world/article.md +++ b/1-js/02-first-steps/01-hello-world/article.md @@ -1,6 +1,6 @@ # Hello, world! -The tutorial that you're reading is about the core Javascript, that is platform-independant. So you'll be able to learn how to use Node.JS and other things based on that knowledge. +The tutorial that you're reading is about the core JavaScript, that is platform-independant. So you'll be able to learn how to use Node.JS and other things based on that knowledge. But we need a working environment to run our scripts, and, just because this book is online, the browser is probably a good choice. We'll use a few browser-specific commands like `alert`, but will keep their amount to the minimum. @@ -133,4 +133,4 @@ The example above can be split into two scripts to work: - A script in an external file can be inserted with ``. -There is much more about browser scripts and their interaction with the web-page. But let's keep in mind that this part of the tutorial is devoted to Javascript language. So we shouldn't distract ourselves from it. We'll be using a browser as a way to run Javascript, very convenient for online reading, but yet one of many. +There is much more about browser scripts and their interaction with the web-page. But let's keep in mind that this part of the tutorial is devoted to JavaScript language. So we shouldn't distract ourselves from it. We'll be using a browser as a way to run JavaScript, very convenient for online reading, but yet one of many. diff --git a/1-js/02-first-steps/05-types/article.md b/1-js/02-first-steps/05-types/article.md index 41d31c5082..1d17b7ce9a 100644 --- a/1-js/02-first-steps/05-types/article.md +++ b/1-js/02-first-steps/05-types/article.md @@ -66,7 +66,7 @@ We'll see more into working with numbers in the chapter . ## A string -A string in Javascript must be quoted. +A string in JavaScript must be quoted. ```js let str = "Hello"; @@ -80,7 +80,7 @@ In JavaScript, there are 3 types of quotes. 2. Single quotes: `'Hello'`. 3. Backticks: `Hello`. -Double and single quotes are "simple" quotes. They mark the beginning and the end of the string, that's all. There's no difference between them in Javascript. +Double and single quotes are "simple" quotes. They mark the beginning and the end of the string, that's all. There's no difference between them in JavaScript. Backticks are "extended functionality" quotes. They allow to embed variables and expressions into a string by wrapping them in `${…}`, for example: diff --git a/1-js/02-first-steps/06-type-conversions/article.md b/1-js/02-first-steps/06-type-conversions/article.md index 8165a55179..2f95537c5f 100644 --- a/1-js/02-first-steps/06-type-conversions/article.md +++ b/1-js/02-first-steps/06-type-conversions/article.md @@ -167,4 +167,4 @@ Most of these rules are easy to understand and memorize. The notable exceptions - `undefined` is `NaN` as a number. - `"0"` is true as a boolean. -Objects are not covered here, we'll return to them later in the chapter , devoted exclusively to objects, after we learn more basic things about Javascript. +Objects are not covered here, we'll return to them later in the chapter , devoted exclusively to objects, after we learn more basic things about JavaScript. diff --git a/1-js/02-first-steps/07-operators/article.md b/1-js/02-first-steps/07-operators/article.md index e5dcd088f9..86195d8ca6 100644 --- a/1-js/02-first-steps/07-operators/article.md +++ b/1-js/02-first-steps/07-operators/article.md @@ -32,7 +32,7 @@ Before we move on, let's grasp the common terminology. ## Strings concatenation, binary + -Now let's see special features of Javascript operators, beyond school arithmetics. +Now let's see special features of JavaScript operators, beyond school arithmetics. Usually the plus operator `'+'` sums numbers. diff --git a/1-js/02-first-steps/09-uibasic/article.md b/1-js/02-first-steps/09-uibasic/article.md index b9f23a301c..c1bd0bae05 100644 --- a/1-js/02-first-steps/09-uibasic/article.md +++ b/1-js/02-first-steps/09-uibasic/article.md @@ -1,6 +1,6 @@ # Interaction: alert, prompt, confirm -This part of the tutorial aims to cover Javascript "as is", without environment-specific tweaks. +This part of the tutorial aims to cover JavaScript "as is", without environment-specific tweaks. But still we use a browser as the demo environment. So we should know at least few user-interface functions. diff --git a/1-js/02-first-steps/14-function-basics/article.md b/1-js/02-first-steps/14-function-basics/article.md index fadffb17b6..8a66512264 100644 --- a/1-js/02-first-steps/14-function-basics/article.md +++ b/1-js/02-first-steps/14-function-basics/article.md @@ -207,7 +207,7 @@ function showMessage(from, text = anotherFunction()) { ````smart header="Default parameters old-style" -Old editions of Javascript did not support default parameters. So there are alternative ways to support them, that you can find mostly in the old scripts. +Old editions of JavaScript did not support default parameters. So there are alternative ways to support them, that you can find mostly in the old scripts. For instance, an explicit check for being `undefined`: @@ -322,7 +322,7 @@ For long expressions, it may be tempting sometimes to put them on a separate lin return (some + long + expression + or + whatever * f(a) + f(b)) ``` -That doesn't work, because Javascript assumes a semicolon after `return` in that case: +That doesn't work, because JavaScript assumes a semicolon after `return` in that case: ```js return*!*;*/!* diff --git a/1-js/02-first-steps/15-function-expressions-arrows/article.md b/1-js/02-first-steps/15-function-expressions-arrows/article.md index e2bb3f7c86..64ce807b28 100644 --- a/1-js/02-first-steps/15-function-expressions-arrows/article.md +++ b/1-js/02-first-steps/15-function-expressions-arrows/article.md @@ -1,6 +1,6 @@ # Function expressions and arrows -In Javascript a function is not a "magical language structure", but a special kind of value. +In JavaScript a function is not a "magical language structure", but a special kind of value. The syntax that we used before is called *Function Declaration*: @@ -159,7 +159,7 @@ ask( Here functions are declared right inside the `ask(...)` call. They have no name, and so are called *anonymous*. Such functions are not accessible outside of `ask`, but that's just what we want here. -Such code appears in our scripts very naturally, it's in the spirit of Javascript. +Such code appears in our scripts very naturally, it's in the spirit of JavaScript. ```smart header="A function is a value representing an \"action\"" diff --git a/1-js/02-first-steps/16-javascript-specials/article.md b/1-js/02-first-steps/16-javascript-specials/article.md index 12a6c255dd..c9880745ab 100644 --- a/1-js/02-first-steps/16-javascript-specials/article.md +++ b/1-js/02-first-steps/16-javascript-specials/article.md @@ -1,4 +1,4 @@ -# Javascript specials +# JavaScript specials This chapter aims to list features of JavaScript that we've learned, paying special attention to subtle moments. @@ -233,7 +233,7 @@ Details in: . ## Functions -We covered 3 ways to create a function in Javascript: +We covered 3 ways to create a function in JavaScript: 1. Function Declaration: the function in the main code flow @@ -291,6 +291,6 @@ More: see , . ## More to come -That was a brief list of Javascript specials that we need to know to code well. +That was a brief list of JavaScript specials that we need to know to code well. -As of now that were only basics. Further in the tutorial you'll find more specials and advanced features of Javascript. +As of now that were only basics. Further in the tutorial you'll find more specials and advanced features of JavaScript. diff --git a/1-js/03-code-quality/01-debugging-chrome/article.md b/1-js/03-code-quality/01-debugging-chrome/article.md index 7e16d22ec9..3e029f1ec4 100644 --- a/1-js/03-code-quality/01-debugging-chrome/article.md +++ b/1-js/03-code-quality/01-debugging-chrome/article.md @@ -54,7 +54,7 @@ Should look like this: ![](chrome-sources-breakpoint.png) -A *breakpoint* is a point of code where the debugger will automatically pause the Javascript execution. +A *breakpoint* is a point of code where the debugger will automatically pause the JavaScript execution. While the code is paused, we can examine current variables, execute commands in the console etc. That is -- debug it. @@ -128,7 +128,7 @@ There are buttons for it at the right-top: The execution has resumed, reached another breakpoint inside `say()` and paused there. Take a look at the "Call stack" at the right. It has increased by one more call. We're inside `say()` now. -- make a step (run the next command), but *not go into the function*, hotkey `key:F10`. -: If we click it now, `alert` will be shown. The important thing is that if `alert` were not native, but a Javascript function, then the execution would "step over it", skipping the function internals. +: If we click it now, `alert` will be shown. The important thing is that if `alert` were not native, but a JavaScript function, then the execution would "step over it", skipping the function internals. -- make a step, hotkey `key:F11`. : The same as the previous one, but "steps in" nested functions. Clicking this will step through all script actions one by one. diff --git a/1-js/03-code-quality/02-coding-style/article.md b/1-js/03-code-quality/02-coding-style/article.md index 1335887d39..f9e9a106f2 100644 --- a/1-js/03-code-quality/02-coding-style/article.md +++ b/1-js/03-code-quality/02-coding-style/article.md @@ -258,7 +258,7 @@ There are many open style guides, so there we could just accept the one we like There exist more there in the wild. -As you become more mature in Javascript programming, you might want to read them all to pick up the common principles. +As you become more mature in JavaScript programming, you might want to read them all to pick up the common principles. ## Style checkers @@ -280,7 +280,7 @@ Here are simple steps to start using it: 1. Install [Node.JS](https://nodejs.org/), necessary to run them. 2. Install eslint: `npm i -g eslint` (npm is Node.JS package installer). -3. Create a config file `.eslintrc` in your Javascript project (the dot at the start is mandatory). +3. Create a config file `.eslintrc` in your JavaScript project (the dot at the start is mandatory). An example of `.eslintrc`: diff --git a/1-js/03-code-quality/03-comments/article.md b/1-js/03-code-quality/03-comments/article.md index d82c7c1df1..bafd2a8d07 100644 --- a/1-js/03-code-quality/03-comments/article.md +++ b/1-js/03-code-quality/03-comments/article.md @@ -182,7 +182,7 @@ For instance, for ESLint you should do the following: 1. Install Node.JS (can take from the ). 2. Install ESLint with the command `npm install -g eslint`. -3. Create a config file named `.eslintrc` in the root of your Javascript project (in the folder that contains all your files). +3. Create a config file named `.eslintrc` in the root of your JavaScript project (in the folder that contains all your files). Here's an example of `.eslintrc`: diff --git a/1-js/03-code-quality/05-testing/article.md b/1-js/03-code-quality/05-testing/article.md index c875cf6c03..6916778cff 100644 --- a/1-js/03-code-quality/05-testing/article.md +++ b/1-js/03-code-quality/05-testing/article.md @@ -36,7 +36,7 @@ Enough words. Let's see the example. Let's say we want to make a function `pow(x, n)` that raises `x` to an integer power `n`. We assume that `n≥0`. -That task is quite simple, there's even a `**` operator in Javascript that can do that, but here we concentrate not on the function itself, but on the development flow, that can be applied to more complex tasks as well. +That task is quite simple, there's even a `**` operator in JavaScript that can do that, but here we concentrate not on the function itself, but on the development flow, that can be applied to more complex tasks as well. Before creating the code of `pow`, we can imagine what the function should do and describe it using BDD. @@ -304,7 +304,7 @@ The basic functionality of `pow` is complete. The first iteration of the develop As it was said, the function `pow(x, n)` is meant to work with positive integer values `n`. -To indicate a mathematical error, Javascript functions usually return `NaN`. Let's do the same for invalid values of `n`. +To indicate a mathematical error, JavaScript functions usually return `NaN`. Let's do the same for invalid values of `n`. Let's first add the behavior to the spec(!): @@ -408,4 +408,4 @@ In real life that's sometimes not that easy. Sometimes it's difficult to write a Later in the tutorial you will meet many tasks with tests baked-in. So you will more practical examples. -Writing tests requires good Javascript knowledge. But we're just starting to learn it. So, to settle down everything, as of now you're not required to write tests, but you should already be able to read them even if they are a little bit more complex than in this chapter. +Writing tests requires good JavaScript knowledge. But we're just starting to learn it. So, to settle down everything, as of now you're not required to write tests, but you should already be able to read them even if they are a little bit more complex than in this chapter. diff --git a/1-js/04-object-basics/01-object/article.md b/1-js/04-object-basics/01-object/article.md index 231041a29c..97d0417100 100644 --- a/1-js/04-object-basics/01-object/article.md +++ b/1-js/04-object-basics/01-object/article.md @@ -1,9 +1,9 @@ # Objects -As we know, there are 7 language types in Javascript. Six of them are called "primitive", because their values contain only a single thing (be it a string or a number or whatever). +As we know, there are 7 language types in JavaScript. Six of them are called "primitive", because their values contain only a single thing (be it a string or a number or whatever). -In contrast, objects are used to store keyed collections of various data and more complex entities. In Javascript, objects penetrate almost every aspect of the language. So we must understand them first before going in-depth anywhere else. +In contrast, objects are used to store keyed collections of various data and more complex entities. In JavaScript, objects penetrate almost every aspect of the language. So we must understand them first before going in-depth anywhere else. [cut] @@ -544,7 +544,7 @@ So, copying an object variable creates one more reference to the same object. But what if we need to duplicate an object? Create an independant copy, a clone? -That's also doable, but a little bit more difficult, because there's no built-in method for that in Javascript. Actually, that's rarely needed, copying by reference is good most of the time. +That's also doable, but a little bit more difficult, because there's no built-in method for that in JavaScript. Actually, that's rarely needed, copying by reference is good most of the time. But if we really want that, then we need to create a new object and replicate the structure of the existing one by iterating over its properties and copying them on the primitive level. @@ -661,7 +661,7 @@ alert(clone.sizes.width); // 51, see the result from the other one To fix that, we should use the cloning loop that examines each value of `user[key]` and, if it's an object, then replicate it's structure as well. That is called a "deep cloning". -There's a standard algorithm for deep cloning that handles the case above and more complex cases, called the [Structured cloning algorithm](w3c.github.io/html/infrastructure.html#internal-structured-cloning-algorithm). Not to reinvent the wheel, we can use a working implementation of it from the Javascript library [lodash](https://lodash.com), the method is called [_.cloneDeep(obj)](https://lodash.com/docs#cloneDeep). +There's a standard algorithm for deep cloning that handles the case above and more complex cases, called the [Structured cloning algorithm](w3c.github.io/html/infrastructure.html#internal-structured-cloning-algorithm). Not to reinvent the wheel, we can use a working implementation of it from the JavaScript library [lodash](https://lodash.com), the method is called [_.cloneDeep(obj)](https://lodash.com/docs#cloneDeep). @@ -688,7 +688,7 @@ To make a "real copy" (a clone) we can use `Object.assign` or [_.cloneDeep(obj) What we've studied in this chapter is called a "plain object", or just `Object`. -There are many other kinds of objects in Javascript: +There are many other kinds of objects in JavaScript: - `Array` to store ordered data collections, - `Date` to store the information about the date and time, diff --git a/1-js/04-object-basics/02-garbage-collection/article.md b/1-js/04-object-basics/02-garbage-collection/article.md index 3968852268..0471ffd00d 100644 --- a/1-js/04-object-basics/02-garbage-collection/article.md +++ b/1-js/04-object-basics/02-garbage-collection/article.md @@ -1,14 +1,14 @@ # Garbage collection -Memory management in Javascript is performed automatically and invisibly to us. We create primitives, objects, functions... All that takes memory. +Memory management in JavaScript is performed automatically and invisibly to us. We create primitives, objects, functions... All that takes memory. -What happens when something is not needed any more? How Javascript engine discovers that and cleans up? +What happens when something is not needed any more? How JavaScript engine discovers that and cleans up? [cut] ## Reachability -The main concept of memory management in Javascript is *reachability*. +The main concept of memory management in JavaScript is *reachability*. Simply put, "reachable" values are those that are accessible or useable somehow. They are guaranteed to be stored in memory. @@ -27,7 +27,7 @@ Simply put, "reachable" values are those that are accessible or useable somehow. For instance, if there's an object in a local variable, and that object has a property referencing another object, that object is considered reachable. And those that it references -- are also reachable. Detailed examples to follow. -There's a background process in the Javascript engine that is called [garbage collector](https://en.wikipedia.org/wiki/Garbage_collection_(computer_science)). It monitors all objects and removes those that became unreachable. +There's a background process in the JavaScript engine that is called [garbage collector](https://en.wikipedia.org/wiki/Garbage_collection_(computer_science)). It monitors all objects and removes those that became unreachable. ## A simple example @@ -185,7 +185,7 @@ Now the objects that could not be visited in the process are considered unreacha That's the concept how garbage collection works. -Javascript engines apply many optimizations to make it run faster and not affect the execution. +JavaScript engines apply many optimizations to make it run faster and not affect the execution. Some of the optimizations: diff --git a/1-js/04-object-basics/03-symbol/article.md b/1-js/04-object-basics/03-symbol/article.md index fa1978d800..6d2949cfd5 100644 --- a/1-js/04-object-basics/03-symbol/article.md +++ b/1-js/04-object-basics/03-symbol/article.md @@ -31,7 +31,7 @@ alert(id1 == id2); // false */!* ``` -If you are familiar with Ruby or another language that also has some sort of "symbols" -- please don't be misguided. Javascript symbols are different. +If you are familiar with Ruby or another language that also has some sort of "symbols" -- please don't be misguided. JavaScript symbols are different. ## "Hidden" properties @@ -48,7 +48,7 @@ user[id] = "ID Value"; alert( user[id] ); // we can access the data using the symbol as the key ``` -Now let's imagine that another script wants to have his own "id" property inside `user`, for his own purposes. That may be another Javascript library, so the scripts are completely unaware for each other. +Now let's imagine that another script wants to have his own "id" property inside `user`, for his own purposes. That may be another JavaScript library, so the scripts are completely unaware for each other. No problem. It can create its own `Symbol("id")`. @@ -178,7 +178,7 @@ Symbols inside the registry are called *global symbols*. If we want an applicati ```smart header="That sounds like Ruby" In some programming languages, like Ruby, there's a single symbol per name. -In Javascript, as we can see, that's right for global symbols. +In JavaScript, as we can see, that's right for global symbols. ``` ### Symbol.keyFor @@ -210,7 +210,7 @@ For non-global symbols, the name is only used for debugging purposes. ## System symbols -There exist many "system" symbols that Javascript uses internally, and we can use them to fine-tune various aspects of our objects. +There exist many "system" symbols that JavaScript uses internally, and we can use them to fine-tune various aspects of our objects. They are listed in the specification in the [Well-known symbols](https://tc39.github.io/ecma262/#sec-well-known-symbols) table: @@ -231,7 +231,7 @@ Other symbols will also become familiar when we study the corresponding language - Symbols are useful if we want to create a field that only those who know the symbol can access. - Symbols don't appear in `for..in` loops. - Symbols created with `Symbol(name)` are always different, even if they have the same name. If we want same-named symbols to be equal, then we should use the global registry: `Symbol.for(name)` returns (creates if needed) a global symbol with the given name. Multiple calls return the same symbol. -- There are system symbols used by Javascript and accessible as `Symbol.*`. We can use them to alter some built-in behaviors. +- There are system symbols used by JavaScript and accessible as `Symbol.*`. We can use them to alter some built-in behaviors. Technically, symbols are not 100% hidden. There is a build-in method [Object.getOwnPropertySymbols(obj)](mdn:js/Object/getOwnPropertySymbols) that allows to get all symbols. Also there is a method named [Reflect.ownKeys(obj)](mdn:js/Reflect/ownKeys) that returns *all* keys of an object including symbolic ones. So they are not really hidden. diff --git a/1-js/04-object-basics/04-object-methods/2-check-syntax/solution.md b/1-js/04-object-basics/04-object-methods/2-check-syntax/solution.md index fc22bac156..e2e87de7c9 100644 --- a/1-js/04-object-basics/04-object-methods/2-check-syntax/solution.md +++ b/1-js/04-object-basics/04-object-methods/2-check-syntax/solution.md @@ -15,7 +15,7 @@ The error message in most browsers does not give understanding what went wrong. **The error appears because a semicolon is missing after `user = {...}`.** -Javascript does not assume a semicolon before a bracket `(user.go)()`, so it reads the code like: +JavaScript does not assume a semicolon before a bracket `(user.go)()`, so it reads the code like: ```js no-beautify let user = { go:... }(user.go)() diff --git a/1-js/04-object-basics/04-object-methods/8-chain-calls/task.md b/1-js/04-object-basics/04-object-methods/8-chain-calls/task.md index 2fe6a67ed0..a989846f52 100644 --- a/1-js/04-object-basics/04-object-methods/8-chain-calls/task.md +++ b/1-js/04-object-basics/04-object-methods/8-chain-calls/task.md @@ -36,4 +36,4 @@ Modify the code of `up` and `down` to make the calls chainable, like this: ladder.up().up().down().showStep(); // 1 ``` -Such approach is widely used across Javascript libraries. +Such approach is widely used across JavaScript libraries. diff --git a/1-js/04-object-basics/04-object-methods/article.md b/1-js/04-object-basics/04-object-methods/article.md index 6078686264..f6061d1713 100644 --- a/1-js/04-object-basics/04-object-methods/article.md +++ b/1-js/04-object-basics/04-object-methods/article.md @@ -11,7 +11,7 @@ let user = { And, in the real world, a user can `act`: to select something from the shopping cart, to login, to logout etc. -Let's implement the same in Javascript using functions in properties. +Let's implement the same in JavaScript using functions in properties. [cut] @@ -164,7 +164,7 @@ If we used `this.name` instead of `user.name` inside the `alert`, then the code ## "this" is not bound -In Javascript, "this" keyword behaves unlike most other programming languages. First, it can be used in any function. +In JavaScript, "this" keyword behaves unlike most other programming languages. First, it can be used in any function. There's no syntax error in the code like that: @@ -227,7 +227,7 @@ Here we are not to judge whether this language design decision is good or bad. W ## Internals: Reference Type ```warn header="In-depth language feature" -This section covers advanced topic that may interest those who want to know Javascript better. +This section covers advanced topic that may interest those who want to know JavaScript better. If you want to go on faster, it can be skipped or postponed. ``` @@ -279,7 +279,7 @@ hi(); // Error, because this is undefined That's because a function is a value of its own. It does not carry the object. So `hi = user.hi` saves it into the variable, and then on the last line it is completely standalone. -**To make `user.hi()` calls work, Javascript uses a trick -- the dot `'.'` returns not a function, but a value of the special [Reference Type](https://tc39.github.io/ecma262/#sec-reference-specification-type).** +**To make `user.hi()` calls work, JavaScript uses a trick -- the dot `'.'` returns not a function, but a value of the special [Reference Type](https://tc39.github.io/ecma262/#sec-reference-specification-type).** The Reference Type is a "specification type". We can't explicitly use it, but it is used internally by the language. diff --git a/1-js/04-object-basics/05-object-toprimitive/article.md b/1-js/04-object-basics/05-object-toprimitive/article.md index e688bca4b7..bd067d89a7 100644 --- a/1-js/04-object-basics/05-object-toprimitive/article.md +++ b/1-js/04-object-basics/05-object-toprimitive/article.md @@ -24,7 +24,7 @@ Still, there are still valid reasons why we should know how to-primitive convers - Simple object-as-string output (`alert` and alike) is useable sometimes. - Many built-in objects implement their own to-primitive conversion, we need to know how to work with that. - Sometimes an unexpected conversion happens, and we should understand what's going on. -- The final one. There are quizzes and questions on interviews that rely on that knowledge. Looks like people think it's a good sign that person understands Javascript if he knows type conversions well. +- The final one. There are quizzes and questions on interviews that rely on that knowledge. Looks like people think it's a good sign that person understands JavaScript if he knows type conversions well. ## ToPrimitive @@ -81,7 +81,7 @@ When a built-in function (like `alert` or mathematical functions) or an operator Please note -- there are only three hints. That simple. There is no "boolean" hint (all objects are `true` in boolean context) or anything else. And if we treat `"default"` and `"number"` the same, like most built-ins do, then there are only two conversions. -**To do the conversion, Javascript tries to find and call three object methods:** +**To do the conversion, JavaScript tries to find and call three object methods:** 1. Call `obj[Symbol.toPrimitive](hint)` if the method exists, 2. Otherwise if hint is `"string"` @@ -126,7 +126,7 @@ As we can see from the code, `user` becomes a self-descriptive string or a money Methods `toString` and `valueOf` come from ancient times. They are not symbols (symbols did not exist that long ago), but rather "regular" string-named methods. They provide an alternative "old-style" way to implement the conversion. -If there's no `Symbol.toPrimitive` then Javascript tries to find them and try in the order: +If there's no `Symbol.toPrimitive` then JavaScript tries to find them and try in the order: - `toString -> valueOf` for "string" hint. - `valueOf -> toString` otherwise. diff --git a/1-js/04-object-basics/06-constructor-new/article.md b/1-js/04-object-basics/06-constructor-new/article.md index b2ff08a018..ca701f2cdc 100644 --- a/1-js/04-object-basics/06-constructor-new/article.md +++ b/1-js/04-object-basics/06-constructor-new/article.md @@ -210,7 +210,7 @@ john = { We can use constructor functions to make multiple similar objects. But the topic is much deeper than described here. So we'll return it later and cover more in-depth. -As of now, it's important to understand what `new` is, because Javascript provides constructor functions for many built-in language objects: like `Date` for dates, `Set` for sets and others that we plan to study. +As of now, it's important to understand what `new` is, because JavaScript provides constructor functions for many built-in language objects: like `Date` for dates, `Set` for sets and others that we plan to study. diff --git a/1-js/05-data-types/01-primitives-methods/article.md b/1-js/05-data-types/01-primitives-methods/article.md index 11c229a931..8325f92204 100644 --- a/1-js/05-data-types/01-primitives-methods/article.md +++ b/1-js/05-data-types/01-primitives-methods/article.md @@ -34,7 +34,7 @@ There exist many built-in objects, including those that work with dates, errors, But features come at a price! -Objects are "heavier" than primitives. They require additional resources to support the internal machinery. But properties and methods are useful in programming, Javascript engines try to optimize them, so the price is usually fair. +Objects are "heavier" than primitives. They require additional resources to support the internal machinery. But properties and methods are useful in programming, JavaScript engines try to optimize them, so the price is usually fair. ## A primitive as an object @@ -85,7 +85,7 @@ We'll see more specific methods in chapters and . ````warn header="Constructors `String/Number/Boolean` are for internal use only" Some languages like Java allow to create "wrapper objects" for primitives explicitly using syntax like `new Number(1)` or `new Boolean(false)`. -In Javascript that's also possible for historical reasons, but highly not recommended. Things will go crazy in many places. +In JavaScript that's also possible for historical reasons, but highly not recommended. Things will go crazy in many places. For instance: diff --git a/1-js/05-data-types/02-number/article.md b/1-js/05-data-types/02-number/article.md index 1cf1bf5bde..46eb5a5ff7 100644 --- a/1-js/05-data-types/02-number/article.md +++ b/1-js/05-data-types/02-number/article.md @@ -331,7 +331,7 @@ There is a special built-in method [Object.is](mdn:js/Object/is) that compares v In all other cases, `Object.is(a, b)` is the same as `a === b`. -This way of comparison is often used in Javascript specification. When an internal algorithm needs to compare two values for being exactly the same, it uses `Object.is` (internally called [SameValue](https://tc39.github.io/ecma262/#sec-samevalue)). +This way of comparison is often used in JavaScript specification. When an internal algorithm needs to compare two values for being exactly the same, it uses `Object.is` (internally called [SameValue](https://tc39.github.io/ecma262/#sec-samevalue)). ``` diff --git a/1-js/05-data-types/03-string/article.md b/1-js/05-data-types/03-string/article.md index 68c228054f..8cc68e803a 100644 --- a/1-js/05-data-types/03-string/article.md +++ b/1-js/05-data-types/03-string/article.md @@ -110,7 +110,7 @@ Of course, that refers only for the quotes that are same as the enclosing ones. alert( `I'm the Walrus!` ); // I'm the Walrus! ``` -Note that the backslash `\` serves for the correct reading of the string by Javascript, then disappears. The in-memory string has no `\`. You can clearly see that in `alert` from the examples above. +Note that the backslash `\` serves for the correct reading of the string by JavaScript, then disappears. The in-memory string has no `\`. You can clearly see that in `alert` from the examples above. But what if we need exactly a backslash `\` in the string? @@ -451,7 +451,7 @@ Let's recap the methods to avoid any confusion: ```smart header="Which one to choose?" -All of them can do the job. Formally, `substr` has a minor drawback: it is described not in the core Javascript specification, but in Annex B, which covers browser-only features that exist mainly for historical reasons. So, non-browser environments may fail to support it. But in practice it works everywhere. +All of them can do the job. Formally, `substr` has a minor drawback: it is described not in the core JavaScript specification, but in Annex B, which covers browser-only features that exist mainly for historical reasons. So, non-browser environments may fail to support it. But in practice it works everywhere. The author finds himself using `slice` almost all the time. ``` @@ -572,7 +572,7 @@ alert( '😂'.length ); // 2, FACE WITH TEARS OF JOY alert( '𩷶'.length ); // 2, a rare chinese hieroglyph ``` -Note that surrogate pairs did not exist at the time when Javascript was created, and thus are not correctly processed by the language! +Note that surrogate pairs did not exist at the time when JavaScript was created, and thus are not correctly processed by the language! We actually have a single symbol in each of the strings above, but the `length` shows the length of `2`. diff --git a/1-js/05-data-types/04-array/article.md b/1-js/05-data-types/04-array/article.md index aaf99be815..27c2300cd0 100644 --- a/1-js/05-data-types/04-array/article.md +++ b/1-js/05-data-types/04-array/article.md @@ -123,7 +123,7 @@ A stack is usually illustrated as a pack of cards: new cards are added to the to For stacks, the latest pushed item is received first, that's also called LIFO (Last-In-First-Out) principle. For queues, we have FIFO (First-In-First-Out). -Arrays in Javascript can work both as a queue and as a stack. They allow to add/remove elements both to/from the beginning or the end. +Arrays in JavaScript can work both as a queue and as a stack. They allow to add/remove elements both to/from the beginning or the end. In computer science the data structure that allows it is called [deque](https://en.wikipedia.org/wiki/Double-ended_queue). @@ -235,7 +235,7 @@ The ways to misuse an array: - Make holes, like: add `arr[0]` and then `arr[1000]` (and nothing between them). - Fill the array in the reverse order, like `arr[1000]`, `arr[999]` and so on. -Please think of arrays as about special structures to work with the *ordered data*. They provide special methods for that. Arrays are carefully tuned inside Javascript engines to work with contiguous ordered data, please use them this way. And if you need arbitrary keys, chances are high that you actually require a regular object `{}`. +Please think of arrays as about special structures to work with the *ordered data*. They provide special methods for that. Arrays are carefully tuned inside JavaScript engines to work with contiguous ordered data, please use them this way. And if you need arbitrary keys, chances are high that you actually require a regular object `{}`. ## Performance diff --git a/1-js/05-data-types/05-array-methods/11-array-unique/solution.md b/1-js/05-data-types/05-array-methods/11-array-unique/solution.md index 9741f5317d..5b565d4230 100644 --- a/1-js/05-data-types/05-array-methods/11-array-unique/solution.md +++ b/1-js/05-data-types/05-array-methods/11-array-unique/solution.md @@ -28,7 +28,7 @@ The method `result.includes(str)` internally walks the array `result` and compar So if there are `100` elements in `result` and no one matches `str`, then it will walk the whole `result` and do exactly `100` comparisons. And if `result` is large, like `10000`, then there would be `10000` comparisons. -That's not a problem by itself, because Javascript engines are very fast, so walk `10000` array is a matter of microseconds. +That's not a problem by itself, because JavaScript engines are very fast, so walk `10000` array is a matter of microseconds. But we do such test for each element of `arr`, in the `for` loop. diff --git a/1-js/05-data-types/06-iterable/article.md b/1-js/05-data-types/06-iterable/article.md index a29e29fb1f..f8e2a322f5 100644 --- a/1-js/05-data-types/06-iterable/article.md +++ b/1-js/05-data-types/06-iterable/article.md @@ -5,7 +5,7 @@ Arrays by themselves are iterable. But not only arrays. Strings are iterable too, and many other built-in objects as well. -Iterables are widely used by the core Javascript, as we'll see many operators and built-in methods rely on them. +Iterables are widely used by the core JavaScript, as we'll see many operators and built-in methods rely on them. [cut] diff --git a/1-js/05-data-types/08-keys-values-entries/article.md b/1-js/05-data-types/08-keys-values-entries/article.md index 259f7e6af4..f18c065b4c 100644 --- a/1-js/05-data-types/08-keys-values-entries/article.md +++ b/1-js/05-data-types/08-keys-values-entries/article.md @@ -32,7 +32,7 @@ For plain objects, the following methods are available: The first difference is that we have to call `Object.keys(obj)`, and not `obj.keys()`. -Why so? There main reason is flexibility. Remember, objects are a base of all complex structures in Javascript. So we may have an object of our own like `order` that implements its own `order.values()` method. And we still can call `Object.values(order)` on it. +Why so? There main reason is flexibility. Remember, objects are a base of all complex structures in JavaScript. So we may have an object of our own like `order` that implements its own `order.values()` method. And we still can call `Object.values(order)` on it. The second difference is that `Object.*` methods return "real" array objects, not just an iterable. That's mainly for historical reasons. diff --git a/1-js/05-data-types/09-destructuring-assignment/article.md b/1-js/05-data-types/09-destructuring-assignment/article.md index 864eb3d8ae..5ff25d90c8 100644 --- a/1-js/05-data-types/09-destructuring-assignment/article.md +++ b/1-js/05-data-types/09-destructuring-assignment/article.md @@ -1,6 +1,6 @@ # Destructuring assignment -The two most used data structures in Javascript are `Object` and `Array`. +The two most used data structures in JavaScript are `Object` and `Array`. Objects allow to pack many pieces of information into a single entity and arrays allow to store ordered collections. So we can make an object or an array and handle it as a single thing, maybe pass to a function call. @@ -326,7 +326,7 @@ let title, width, height; {title, width, height} = {title: "Menu", width: 200, height: 100}; ``` -The problem is that Javascript treats `{...}` in the main code flow (not inside another expression) as a code block. Such code blocks can be used to group statements, like this: +The problem is that JavaScript treats `{...}` in the main code flow (not inside another expression) as a code block. Such code blocks can be used to group statements, like this: ```js run { @@ -337,7 +337,7 @@ The problem is that Javascript treats `{...}` in the main code flow (not inside } ``` -To show Javascript that it's not a code block, we can wrap the whole assignment in brackets `(...)`: +To show JavaScript that it's not a code block, we can wrap the whole assignment in brackets `(...)`: ```js run let title, width, height; diff --git a/1-js/05-data-types/10-date/article.md b/1-js/05-data-types/10-date/article.md index d229e137b1..3117573e3d 100644 --- a/1-js/05-data-types/10-date/article.md +++ b/1-js/05-data-types/10-date/article.md @@ -408,7 +408,7 @@ alert( date ); Note that unlike many other systems, timestamps in JavaScript are in milliseconds, not in seconds. -Also, sometimes we need more precise time measurements. Javascript itself does not have a way to measure time in microseconds (1 millionth of a second), but most environments provide it. +Also, sometimes we need more precise time measurements. JavaScript itself does not have a way to measure time in microseconds (1 millionth of a second), but most environments provide it. For instance, browser has [performance.now()](mdn:api/Performance/now) that gives the number of milliseconds from the start of page loading, but adds 3 digits after the point to it. So totally it becomes microsecond percision: diff --git a/1-js/05-data-types/11-json/article.md b/1-js/05-data-types/11-json/article.md index 7d540ff0fa..7b76725b03 100644 --- a/1-js/05-data-types/11-json/article.md +++ b/1-js/05-data-types/11-json/article.md @@ -29,9 +29,9 @@ Luckily, there's no need to write the code to handle all this. The task has been ## JSON.stringify -The [JSON](http://en.wikipedia.org/wiki/JSON) (JavaScript Object Notation) is a general format to represent values and objects. It is described as in [RFC 4627](http://tools.ietf.org/html/rfc4627) standard. Initially it was made for Javascript, but many other languages have libraries to handle it as well. So it's easy to use JSON for data exchange when the client uses Javascript and the server is written on Ruby/PHP/Java/Whatever. +The [JSON](http://en.wikipedia.org/wiki/JSON) (JavaScript Object Notation) is a general format to represent values and objects. It is described as in [RFC 4627](http://tools.ietf.org/html/rfc4627) standard. Initially it was made for JavaScript, but many other languages have libraries to handle it as well. So it's easy to use JSON for data exchange when the client uses JavaScript and the server is written on Ruby/PHP/Java/Whatever. -Javascript provides methods: +JavaScript provides methods: - `JSON.stringify` to convert objects into JSON. - `JSON.parse` to convert JSON back into an object. @@ -102,7 +102,7 @@ alert( JSON.stringify(true) ); // true alert( JSON.stringify([1, 2, 3]) ); // [1,2,3] ``` -JSON is data-only cross-language specification, so some Javascript-specific object properties are skipped by `JSON.stringify`. +JSON is data-only cross-language specification, so some JavaScript-specific object properties are skipped by `JSON.stringify`. Namely: @@ -292,7 +292,7 @@ The third argument of `JSON.stringify(value, replacer, spaces)` is the number of Previously, all stringified objects had no indents and extra spaces. That's fine if we want to send an object over a network. The `spacer` argument is used exclusively for a nice output. -Here `spacer = 2` tells Javascript to show nested objects on multiple lines, with indentation of 2 spaces inside an object: +Here `spacer = 2` tells JavaScript to show nested objects on multiple lines, with indentation of 2 spaces inside an object: ```js run let user = { @@ -463,7 +463,7 @@ It looks like this: let str = '{"title":"Conference","date":"2017-11-30T12:00:00.000Z"}'; ``` -...And now we reed to *deserialize* it, to turn back into Javascript object. +...And now we reed to *deserialize* it, to turn back into JavaScript object. Let's do it by calling `JSON.parse`: @@ -522,6 +522,6 @@ alert( schedule.meetups[1].date.getDate() ); // works! - JSON is a data format that has its own independent standard and libraries for most programming languages. - JSON supports plain objects, arrays, strings, numbers, booleans and `null`. -- Javascript provides methods [JSON.stringify](mdn:js/JSON/stringify) to serialize into JSON and [JSON.parse](mdn:js/JSON/parse) to read from JSON. +- JavaScript provides methods [JSON.stringify](mdn:js/JSON/stringify) to serialize into JSON and [JSON.parse](mdn:js/JSON/parse) to read from JSON. - Both methods support transformer functions for smart reading/writing. - If an object has `toJSON`, then it is called by `JSON.stringify`. diff --git a/1-js/06-more-functions/01-recursion/01-sum-to/solution.md b/1-js/06-more-functions/01-recursion/01-sum-to/solution.md index b8f753d5b9..237b9ef9e4 100644 --- a/1-js/06-more-functions/01-recursion/01-sum-to/solution.md +++ b/1-js/06-more-functions/01-recursion/01-sum-to/solution.md @@ -37,4 +37,4 @@ P.S. Naturally, the formula is the fastest solution. It uses only 3 operations f The loop variant is the second in terms of speed. In both the recursive and the loop variant we sum the same numbers. But the recursion involves nested calls and execution stack management. That also takes resources, so it's slower. -P.P.S. The standard describes a "tail call" optimization: if the recursive call is the very last one in the function (like in `sumTo` above), then the outer function will not need to resume the execution and we don't need to remember its execution context. In that case `sumTo(100000)` is countable. But if your Javascript engine does not support it, there will be an error: maximum stack size exceeded, because there's usually a limitation on the total stack size. +P.P.S. The standard describes a "tail call" optimization: if the recursive call is the very last one in the function (like in `sumTo` above), then the outer function will not need to resume the execution and we don't need to remember its execution context. In that case `sumTo(100000)` is countable. But if your JavaScript engine does not support it, there will be an error: maximum stack size exceeded, because there's usually a limitation on the total stack size. diff --git a/1-js/06-more-functions/01-recursion/article.md b/1-js/06-more-functions/01-recursion/article.md index 89568b0709..8401b5f09c 100644 --- a/1-js/06-more-functions/01-recursion/article.md +++ b/1-js/06-more-functions/01-recursion/article.md @@ -98,7 +98,7 @@ function pow(x, n) { The maximal number of nested calls (including the first one) is called *recursion depth*. In our case, it there will be exactly `n`. -The maximal recursion depth is limited by Javascript engine. We can make sure about 10000, some engines allow more, but 100000 is probably out of limit for the majority of them. There are automatic optimizations that help to alleviate this ("tail calls optimizations"), but they are not yet supported everywhere and work only in simple cases. +The maximal recursion depth is limited by JavaScript engine. We can make sure about 10000, some engines allow more, but 100000 is probably out of limit for the majority of them. There are automatic optimizations that help to alleviate this ("tail calls optimizations"), but they are not yet supported everywhere and work only in simple cases. That limits the application of recursion, but it still remains very wide. There are many tasks where recursive way of thinking gives simpler code, easier to maintain. @@ -164,7 +164,7 @@ To calculate `x*pow(x, n-1)`, we need to make a subcall of `pow` with new argume ### pow(2, 2) -To do a nested call, Javascript remembers the current execution context in the *execution context stack*. +To do a nested call, JavaScript remembers the current execution context in the *execution context stack*. Here we call the same function `pow`, but it absolutely doesn't matter. The process is the same for all functions: diff --git a/1-js/06-more-functions/02-rest-parameters-spread-operator/article.md b/1-js/06-more-functions/02-rest-parameters-spread-operator/article.md index c13d755db6..cbe60c4329 100644 --- a/1-js/06-more-functions/02-rest-parameters-spread-operator/article.md +++ b/1-js/06-more-functions/02-rest-parameters-spread-operator/article.md @@ -1,6 +1,6 @@ # Rest parameters and spread operator -Many Javascript built-in functions support on arbitrary number of arguments. +Many JavaScript built-in functions support on arbitrary number of arguments. For instance: diff --git a/1-js/06-more-functions/03-closure/article.md b/1-js/06-more-functions/03-closure/article.md index b7806d7315..ed95f94848 100644 --- a/1-js/06-more-functions/03-closure/article.md +++ b/1-js/06-more-functions/03-closure/article.md @@ -1,7 +1,7 @@ # Closure -Javascript is a very function-oriented language, it gives a lot of freedom. A function can be created at one moment, then passed as a value to another variable or function and called from a totally different place much later. +JavaScript is a very function-oriented language, it gives a lot of freedom. A function can be created at one moment, then passed as a value to another variable or function and called from a totally different place much later. We know that a function can access variables outside of it. And this feature is used quite often. @@ -9,7 +9,7 @@ But what happens when outer variables change? Does a function get a new value or Also, what happens when a variable with the function travels to another place of the code and is called from there -- will it get access to outer variables in the new place? -There is no general programming answer for these questions. Different languages behave differently. Here we'll cover Javascript. +There is no general programming answer for these questions. Different languages behave differently. Here we'll cover JavaScript. [cut] @@ -65,7 +65,7 @@ Let's formulate two questions for the seed, and then study internal mechanics pi To understand what's going on, let's first discuss what a "variable" technically is. -In Javascript, every running function, code block and the script as a whole have an associated object named *Lexical Environment*. +In JavaScript, every running function, code block and the script as a whole have an associated object named *Lexical Environment*. The Lexical Environment object consists of two parts: @@ -186,7 +186,7 @@ And if a function is called multiple times, then each invocation will have its o ``` ```smart header="Lexical Environment is a specification object" -"Lexical Environment" is a specification object. We can't get this object in our code and manipulate it directly. Javascript engines also may optimize it, discard variables that are unused in the code and perform other stuff. +"Lexical Environment" is a specification object. We can't get this object in our code and manipulate it directly. JavaScript engines also may optimize it, discard variables that are unused in the code and perform other stuff. ``` @@ -361,11 +361,11 @@ So, the result is `"Pete"` here. ```smart header="Closures" There is a general programming term "closure", that developers generally should know. -A [closure](https://en.wikipedia.org/wiki/Closure_(computer_programming)) is a function that remembers its outer variables and can access them. In some languages, that's not possible, or a function should be written in a special way to make it happen. But as explained above, in Javascript all functions are naturally closures (there is only one exclusion, to be covered in ). +A [closure](https://en.wikipedia.org/wiki/Closure_(computer_programming)) is a function that remembers its outer variables and can access them. In some languages, that's not possible, or a function should be written in a special way to make it happen. But as explained above, in JavaScript all functions are naturally closures (there is only one exclusion, to be covered in ). That is: they automatically remember where they are created using a hidden `[[Environment]]` property, and all of them can access outer variables. -When on an interview a frontend developer gets a question about "what's a closure?", a valid answer would be a definition of the closure and an explanation that all functions in Javascript are closures, and maybe few more words about technical details: the `[[Environment]]` property and how Lexical Environments work. +When on an interview a frontend developer gets a question about "what's a closure?", a valid answer would be a definition of the closure and an explanation that all functions in JavaScript are closures, and maybe few more words about technical details: the `[[Environment]]` property and how Lexical Environments work. ``` ## Code blocks and loops, IIFE @@ -439,7 +439,7 @@ They look like this: Here a Function Expression is created and immediately called. So the code executes right now and has its own private variables. -The Function Expression is wrapped with brackets `(function {...})`, because when Javascript meets `"function"` in the main code flow, it understands it as a start of Function Declaration. But a Function Declaration must have a name, so there will be an error: +The Function Expression is wrapped with brackets `(function {...})`, because when JavaScript meets `"function"` in the main code flow, it understands it as a start of Function Declaration. But a Function Declaration must have a name, so there will be an error: ```js run // Error: Unexpected token ( @@ -452,7 +452,7 @@ function() { // <-- JavaScript cannot find function name, meets ( and gives erro }(); ``` -We can say "okay, let it be Function Declaration, let's add a name", but it won't work. Javascript does not allow Function Declarations to be called immediately: +We can say "okay, let it be Function Declaration, let's add a name", but it won't work. JavaScript does not allow Function Declarations to be called immediately: ```js run // syntax error because of brackets below @@ -461,9 +461,9 @@ function go() { }(); // <-- can't call Function Declaration immediately ``` -So the brackets are needed to show Javascript that the function is created in the context of another expression, and hence it's a Function Expression. Needs no name and can be called immediately. +So the brackets are needed to show JavaScript that the function is created in the context of another expression, and hence it's a Function Expression. Needs no name and can be called immediately. -There are other ways to tell Javascript that we mean Function Expression: +There are other ways to tell JavaScript that we mean Function Expression: ```js run // Ways to create IIFE @@ -555,7 +555,7 @@ Lexical Environment objects that we've been talking about are subjects to same m As we've seen, in theory while a function is alive, all outer variabels are also retained. -But in practice, Javascript engines try to optimize that. They analyze variable usage and if it's easy to see that an outer variable is not used -- it is removed. +But in practice, JavaScript engines try to optimize that. They analyze variable usage and if it's easy to see that an outer variable is not used -- it is removed. **An important side effect in V8 (Chrome, Opera) is that such variable will become unavailable in debugging.** @@ -677,7 +677,7 @@ alert(phrase); // Error, phrase is not defined alert(phrase); // Error: phrase is not defined ``` - As we can see, `var` pierces through `if`, `for` or other code blocks. That's because long time ago in Javascript blocks had no Lexical Environments. And `var` is a reminiscence of that. + As we can see, `var` pierces through `if`, `for` or other code blocks. That's because long time ago in JavaScript blocks had no Lexical Environments. And `var` is a reminiscence of that. `var` declarations are processed when the function starts (or script starts for globals). : In other words, `var` variables are defined from the beginning of the function. diff --git a/1-js/06-more-functions/04-global-object/article.md b/1-js/06-more-functions/04-global-object/article.md index b1f4dada92..9388960b8f 100644 --- a/1-js/06-more-functions/04-global-object/article.md +++ b/1-js/06-more-functions/04-global-object/article.md @@ -2,9 +2,9 @@ # Global object -When Javascript was created, there was an idea of a "global object" that provides all global variables and functions. It was planned that multiple in-browser scripts would use that single global object and share variables through it. +When JavaScript was created, there was an idea of a "global object" that provides all global variables and functions. It was planned that multiple in-browser scripts would use that single global object and share variables through it. -Since then, Javascript greatly evolved, and that idea of linking code through global variables became much less appealing. In modern Javascript, the concept of modules too its place. +Since then, JavaScript greatly evolved, and that idea of linking code through global variables became much less appealing. In modern JavaScript, the concept of modules too its place. But the global object still remains in the specification. @@ -119,7 +119,7 @@ Usually, it's not a good idea to use it, but here are some examples you can meet 3. To take the variable from the right window. That's probably the most valid use case. - A browser may open multiple windows and tabs. A window may also embed another one in `