From 8491866a87641708ee4253a1b89b5d8a0243d426 Mon Sep 17 00:00:00 2001 From: Bimochan Shrestha Date: Tue, 21 Jan 2020 14:13:48 +0545 Subject: [PATCH 01/11] Change argument name from inner variable name --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 950f1d20..1a03e71a 100644 --- a/README.md +++ b/README.md @@ -543,7 +543,7 @@ const menuConfig = { }; function createMenu(config) { - config = Object.assign( + let finalConfig = Object.assign( { title: "Foo", body: "Bar", @@ -552,7 +552,7 @@ function createMenu(config) { }, config ); - + return finalConfig // config now equals: {title: "Order", body: "Bar", buttonText: "Send", cancellable: true} // ... } From ec7baf25c13147d62d175d9518d24aa2fff56cc1 Mon Sep 17 00:00:00 2001 From: Denis Date: Wed, 1 Apr 2020 18:47:12 +0300 Subject: [PATCH 02/11] Fix calling animationModule in ISP bad example --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0bfe4c85..61890f35 100644 --- a/README.md +++ b/README.md @@ -1672,7 +1672,7 @@ class DOMTraverser { setup() { this.rootNode = this.settings.rootNode; - this.animationModule.setup(); + this.settings.animationModule.setup(); } traverse() { From 365717f8bb54f0046e226606b0bbd3c9123e3594 Mon Sep 17 00:00:00 2001 From: Yaniv Chekroun Date: Sun, 6 Sep 2020 15:23:12 +0300 Subject: [PATCH 03/11] Add calculation for milliseconds in a day --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 23ffbd33..fbe4de71 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,7 @@ setTimeout(blastOff, 86400000); ```javascript // Declare them as capitalized named constants. -const MILLISECONDS_IN_A_DAY = 86_400_000; +const MILLISECONDS_IN_A_DAY = 60 * 60 * 24 * 1000; //86400000; setTimeout(blastOff, MILLISECONDS_IN_A_DAY); ``` From 3b9504ef2ac585fadeec0523bb22ca39ca626e6b Mon Sep 17 00:00:00 2001 From: "J.D. Sandifer" Date: Sun, 4 Oct 2020 20:50:25 -0700 Subject: [PATCH 04/11] Replace pass-by-reference with mutability, clean up This edit only affects the Avoid Side Effects (part 2) section. It replaces the discussion of pass by reference with an explanation in terms of mutability. By avoiding the confusing terminology and possible links to the implementation details of different JS engines the explanation can be kept at an abstraction level that's great for beginners and experts alike. I also cleaned up some grammar, typos, etc. --- README.md | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 23ffbd33..a67a044b 100644 --- a/README.md +++ b/README.md @@ -643,26 +643,29 @@ console.log(newName); // ['Ryan', 'McDermott']; ### Avoid Side Effects (part 2) -In JavaScript, primitives are passed by value and objects/arrays are passed by -reference. In the case of objects and arrays, if your function makes a change -in a shopping cart array, for example, by adding an item to purchase, -then any other function that uses that `cart` array will be affected by this -addition. That may be great, however it can be bad too. Let's imagine a bad -situation: +In JavaScript, some values are unchangeable (immutable) and some are changeable +(mutable). Objects and arrays are two kinds of mutable values so it's important +to handle them carefully when they're passed as parameters to a function. A +JavaScript function can change an object's properties or alter the contents of +an array which could easily cause bugs elsewhere. + +Suppose there's a function that accepts an array parameter representing a +shopping cart. If the function makes a change in that shopping cart array +- by adding an item to purchase, for example - then any other function that +uses that same `cart` array will be affected by this addition. That may be +great, however it could also be bad. Let's imagine a bad situation: The user clicks the "Purchase" button which calls a `purchase` function that spawns a network request and sends the `cart` array to the server. Because of a bad network connection, the `purchase` function has to keep retrying the -request. Now, what if in the meantime the user accidentally clicks "Add to Cart" +request. Now, what if in the meantime the user accidentally clicks an "Add to Cart" button on an item they don't actually want before the network request begins? If that happens and the network request begins, then that purchase function -will send the accidentally added item because it has a reference to a shopping -cart array that the `addItemToCart` function modified by adding an unwanted -item. +will send the accidentally added item because the `cart` array was modified. -A great solution would be for the `addItemToCart` to always clone the `cart`, -edit it, and return the clone. This ensures that no other functions that are -holding onto a reference of the shopping cart will be affected by any changes. +A great solution would be for the `addItemToCart` function to always clone the +`cart`, edit it, and return the clone. This would ensure that functions that are still +using the old shopping cart wouldn't be affected by the changes. Two caveats to mention to this approach: From 30282195952b7eb01d2c8e0f022f83d60cde9284 Mon Sep 17 00:00:00 2001 From: "J.D. Sandifer" Date: Wed, 7 Oct 2020 20:15:53 -0700 Subject: [PATCH 05/11] Fix stray hyphen turning into a random bullet --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a67a044b..e5b63a81 100644 --- a/README.md +++ b/README.md @@ -650,8 +650,8 @@ JavaScript function can change an object's properties or alter the contents of an array which could easily cause bugs elsewhere. Suppose there's a function that accepts an array parameter representing a -shopping cart. If the function makes a change in that shopping cart array -- by adding an item to purchase, for example - then any other function that +shopping cart. If the function makes a change in that shopping cart array - +by adding an item to purchase, for example - then any other function that uses that same `cart` array will be affected by this addition. That may be great, however it could also be bad. Let's imagine a bad situation: From 029c4c2f8aef211caa99ab4cd39dcdbd496ba669 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milo=C5=A1=20Doskovi=C4=87?= <40147841+doskovicmilos@users.noreply.github.com> Date: Sat, 10 Oct 2020 18:04:42 +0200 Subject: [PATCH 06/11] Add Serbian translation. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 6205f631..ad21e9aa 100644 --- a/README.md +++ b/README.md @@ -2377,6 +2377,7 @@ This is also available in other languages: - [maksugr/clean-code-javascript](https://github.com/maksugr/clean-code-javascript) - ![es](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Spain.png) **Spanish**: [tureey/clean-code-javascript](https://github.com/tureey/clean-code-javascript) - ![es](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Uruguay.png) **Spanish**: [andersontr15/clean-code-javascript](https://github.com/andersontr15/clean-code-javascript-es) +- ![rs](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Serbia.png) **Serbian**: [doskovicmilos/clean-code-javascript/](https://github.com/doskovicmilos/clean-code-javascript) - ![tr](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Turkey.png) **Turkish**: [bsonmez/clean-code-javascript](https://github.com/bsonmez/clean-code-javascript/tree/turkish-translation) - ![ua](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Ukraine.png) **Ukrainian**: [mindfr1k/clean-code-javascript-ua](https://github.com/mindfr1k/clean-code-javascript-ua) - ![vi](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Vietnam.png) **Vietnamese**: [hienvd/clean-code-javascript/](https://github.com/hienvd/clean-code-javascript/) From 753d6d8b33dece69e08b2ec0ea0807592881fbf2 Mon Sep 17 00:00:00 2001 From: James Tharpe Date: Mon, 29 Mar 2021 08:38:27 -0400 Subject: [PATCH 07/11] Make example more succinct "PER" has the same meaning as "IN_A" but is less verbose --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ad21e9aa..71896ed4 100644 --- a/README.md +++ b/README.md @@ -100,9 +100,9 @@ setTimeout(blastOff, 86400000); ```javascript // Declare them as capitalized named constants. -const MILLISECONDS_IN_A_DAY = 60 * 60 * 24 * 1000; //86400000; +const MILLISECONDS_PER_DAY = 60 * 60 * 24 * 1000; //86400000; -setTimeout(blastOff, MILLISECONDS_IN_A_DAY); +setTimeout(blastOff, MILLISECONDS_PER_DAY); ``` **[⬆ back to top](#table-of-contents)** From 3ff9eba6d460f31db8146762bade4fcc32626762 Mon Sep 17 00:00:00 2001 From: Ryan McDermott Date: Sun, 23 May 2021 11:52:44 -0700 Subject: [PATCH 08/11] Fix `paintCar` example to include `color` as param --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 71896ed4..631db6e8 100644 --- a/README.md +++ b/README.md @@ -180,8 +180,8 @@ const Car = { carColor: "Blue" }; -function paintCar(car) { - car.carColor = "Red"; +function paintCar(car, color) { + car.carColor = color; } ``` @@ -194,8 +194,8 @@ const Car = { color: "Blue" }; -function paintCar(car) { - car.color = "Red"; +function paintCar(car, color) { + car.color = color; } ``` From 384665f8da2de749ad96c694a9e18227cfd08b45 Mon Sep 17 00:00:00 2001 From: Hamed Abdollahi <42994875+hamettio@users.noreply.github.com> Date: Fri, 23 Jul 2021 19:04:42 +0200 Subject: [PATCH 09/11] Persian translation added (Fluent + RTL styled) --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 631db6e8..52e2e786 100644 --- a/README.md +++ b/README.md @@ -2381,5 +2381,6 @@ This is also available in other languages: - ![tr](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Turkey.png) **Turkish**: [bsonmez/clean-code-javascript](https://github.com/bsonmez/clean-code-javascript/tree/turkish-translation) - ![ua](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Ukraine.png) **Ukrainian**: [mindfr1k/clean-code-javascript-ua](https://github.com/mindfr1k/clean-code-javascript-ua) - ![vi](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Vietnam.png) **Vietnamese**: [hienvd/clean-code-javascript/](https://github.com/hienvd/clean-code-javascript/) +- ![ir](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Iran.png) **Persian**: [hamettio/clean-code-javascript](https://github.com/hamettio/clean-code-javascript) **[⬆ back to top](#table-of-contents)** From 98f1d4a5a3b00c7b201400db6a443817d759859b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eug=C3=A8ne=20d=27Augier?= <101138826+eugene-augier@users.noreply.github.com> Date: Wed, 13 Apr 2022 14:08:10 +0200 Subject: [PATCH 10/11] French translation --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 631db6e8..3c06041e 100644 --- a/README.md +++ b/README.md @@ -2365,7 +2365,7 @@ This is also available in other languages: - [alivebao/clean-code-js](https://github.com/alivebao/clean-code-js) - [beginor/clean-code-javascript](https://github.com/beginor/clean-code-javascript) - ![tw](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Taiwan.png) **Traditional Chinese**: [AllJointTW/clean-code-javascript](https://github.com/AllJointTW/clean-code-javascript) -- ![fr](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/France.png) **French**: [GavBaros/clean-code-javascript-fr](https://github.com/GavBaros/clean-code-javascript-fr) +- ![fr](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/France.png) **French**: [eugene-augier/clean-code-javascript-fr](https://github.com/eugene-augier/clean-code-javascript-fr) - ![de](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Germany.png) **German**: [marcbruederlin/clean-code-javascript](https://github.com/marcbruederlin/clean-code-javascript) - ![id](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Indonesia.png) **Indonesia**: [andirkh/clean-code-javascript/](https://github.com/andirkh/clean-code-javascript/) - ![it](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Italy.png) **Italian**: [frappacchio/clean-code-javascript/](https://github.com/frappacchio/clean-code-javascript/) From 2cab77b8e58dce3f6c418595b7ef70adca1a4258 Mon Sep 17 00:00:00 2001 From: Agil Atakishiyev Date: Sun, 10 Jul 2022 21:05:45 +0400 Subject: [PATCH 11/11] fixed naming --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 631db6e8..e2880d99 100644 --- a/README.md +++ b/README.md @@ -201,9 +201,9 @@ function paintCar(car, color) { **[⬆ back to top](#table-of-contents)** -### Use default arguments instead of short circuiting or conditionals +### Use default parameters instead of short circuiting or conditionals -Default arguments are often cleaner than short circuiting. Be aware that if you +Default parameters are often cleaner than short circuiting. Be aware that if you use them, your function will only provide default values for `undefined` arguments. Other "falsy" values such as `''`, `""`, `false`, `null`, `0`, and `NaN`, will not be replaced by a default value.