From a8dab707f4d1c45fec6af166cdee5fa92b58568b Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Thu, 7 Mar 2024 19:11:09 +0000 Subject: [PATCH 01/12] Update README file --- README.md | 152 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 92 insertions(+), 60 deletions(-) diff --git a/README.md b/README.md index 0f66720755..0acef98028 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ Other Style Guides 1. [Accessors](#accessors) 1. [Events](#events) 1. [jQuery](#jquery) - 1. [ECMAScript 5 Compatibility](#ecmascript-5-compatibility) + 1. [ECMAScript 6 Compatibility](#ecmascript-6-compatibility) 1. [ECMAScript 6+ (ES 2015+) Styles](#ecmascript-6-es-2015-styles) 1. [Standard Library](#standard-library) 1. [Testing](#testing) @@ -374,9 +374,8 @@ Other Style Guides // bad const len = items.length; const itemsCopy = []; - let i; - for (i = 0; i < len; i += 1) { + for (let i = 0; i < len; i += 1) { itemsCopy[i] = items[i]; } @@ -412,7 +411,7 @@ Other Style Guides ``` - - [4.6](#arrays--mapping) Use [`Array.from`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/from) instead of spread `...` for mapping over iterables, because it avoids creating an intermediate array. + - [4.6](#arrays--mapping) Use [`Array.from`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/from) instead of spread `...` for mapping over iterables like Sets, Maps or NodeLists, because it avoids creating an intermediate array. ```javascript // bad @@ -710,9 +709,8 @@ Other Style Guides } // good - let test; if (currentUser) { - test = () => { + let test = () => { console.log('Yup.'); }; } @@ -740,13 +738,13 @@ Other Style Guides ```javascript // bad - function concatenateAll() { + function concatenateAllStrings() { const args = Array.prototype.slice.call(arguments); return args.join(''); } // good - function concatenateAll(...args) { + function concatenateAllStrings(...args) { return args.join(''); } ``` @@ -854,6 +852,11 @@ Other Style Guides function f2(obj) { const key = Object.prototype.hasOwnProperty.call(obj, 'key') ? obj.key : 1; } + + // best + function f2(obj) { + const key = Object.hasOwn(obj, 'key') ? obj.key : 1; + } ``` @@ -1031,9 +1034,9 @@ Other Style Guides ``` - - [8.4](#arrows--one-arg-parens) Always include parentheses around arguments for clarity and consistency. eslint: [`arrow-parens`](https://eslint.org/docs/rules/arrow-parens) + - [8.4](#arrows--one-arg-parens) Always include parentheses around parameters for clarity and consistency. eslint: [`arrow-parens`](https://eslint.org/docs/rules/arrow-parens) - > Why? Minimizes diff churn when adding or removing arguments. + > Why? Minimizes diff churn when adding or removing parameters. ```javascript // bad @@ -1129,6 +1132,7 @@ Other Style Guides constructor(contents = []) { this.queue = [...contents]; } + pop() { const value = this.queue[0]; this.queue.splice(0, 1); @@ -1194,8 +1198,7 @@ Other Style Guides const luke = new Jedi(); - luke.jump() - .setHeight(20); + luke.jump().setHeight(20); ``` @@ -1326,7 +1329,7 @@ Other Style Guides ``` - - [10.2](#modules--no-wildcard) Do not use wildcard imports. + - [10.2](#modules--no-wildcard) Do not use wildcard imports unless you have multiple named exports and want to import all of them as single object. > Why? This makes sure you have a single default export. @@ -1479,7 +1482,7 @@ Other Style Guides ## Iterators and Generators - - [11.1](#iterators--nope) Don’t use iterators. Prefer JavaScript’s higher-order functions instead of loops like `for-in` or `for-of`. eslint: [`no-iterator`](https://eslint.org/docs/rules/no-iterator) [`no-restricted-syntax`](https://eslint.org/docs/rules/no-restricted-syntax) + - [11.1](#iterators--nope) Don’t use iterators. Prefer JavaScript’s higher-order functions instead of loops like `for`, `for-in` or `for-of`. eslint: [`no-iterator`](https://eslint.org/docs/rules/no-iterator) [`no-restricted-syntax`](https://eslint.org/docs/rules/no-restricted-syntax) > Why? This enforces our immutable rule. Dealing with pure functions that return values is easier to reason about than side effects. @@ -1493,18 +1496,18 @@ Other Style Guides for (let num of numbers) { sum += num; } - sum === 15; + sum === 15; // true // good let sum = 0; numbers.forEach((num) => { sum += num; }); - sum === 15; + sum === 15; // true // best (use the functional force) const sum = numbers.reduce((total, num) => total + num, 0); - sum === 15; + sum === 15; // true // bad const increasedByOne = []; @@ -1640,12 +1643,22 @@ Other Style Guides ## Variables - - [13.1](#variables--const) Always use `const` or `let` to declare variables. Not doing so will result in global variables. We want to avoid polluting the global namespace. Captain Planet warned us of that. eslint: [`no-undef`](https://eslint.org/docs/rules/no-undef) [`prefer-const`](https://eslint.org/docs/rules/prefer-const) + - [13.1](#variables--const) Always use `const` or `let` to declare variables. Not doing so will result in global variables in case strict mode is disabled. We want to avoid polluting the global namespace. Captain Planet warned us of that. eslint: [`no-undef`](https://eslint.org/docs/rules/no-undef) [`prefer-const`](https://eslint.org/docs/rules/prefer-const) + + > Note: The entire contents of JavaScript modules are automatically in [strict mode](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode) and therefore usage of the undeclared variables will not lead to creation of the global variables ```javascript // bad superPower = new SuperPower(); + // bad + function foo() { + bar = 10 // bar will appear in the global scope + } + + foo() + console.log(bar) // 10 + // good const superPower = new SuperPower(); ``` @@ -1741,7 +1754,7 @@ Other Style Guides - [13.5](#variables--no-chain-assignment) Don’t chain variable assignments. eslint: [`no-multi-assign`](https://eslint.org/docs/rules/no-multi-assign) - > Why? Chaining variable assignments creates implicit global variables. + > Why? Chaining variable assignments creates implicit global variables in case [strict mode](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode) is disabled. ```javascript // bad @@ -1778,7 +1791,6 @@ Other Style Guides ```javascript // bad - const array = [1, 2, 3]; let num = 1; num++; @@ -1795,7 +1807,6 @@ Other Style Guides } // good - const array = [1, 2, 3]; let num = 1; num += 1; @@ -1835,7 +1846,6 @@ Other Style Guides ```javascript // bad - const some_unused_var = 42; // Write-only variables are not considered as used. @@ -1852,7 +1862,6 @@ Other Style Guides } // good - function getXPlusY(x, y) { return x + y; } @@ -2091,7 +2100,7 @@ Other Style Guides let x = 1; break; case 2: - const y = 2; + const x = 2; // SyntaxError: Identifier 'x' has already been declared break; case 3: function f() { @@ -2109,7 +2118,7 @@ Other Style Guides break; } case 2: { - const y = 2; + const x = 2; // No SyntaxError break; } case 3: { @@ -2156,7 +2165,7 @@ Other Style Guides const foo = a ? a : b; const bar = c ? true : false; const baz = c ? false : true; - const quux = a != null ? a : b; + const quux = (a !== undefined && a !== null) ? a : b; // good const foo = a || b; @@ -2208,25 +2217,32 @@ Other Style Guides > Why? It provides precision by distinguishing null/undefined from other falsy values, enhancing code clarity and predictability. ```javascript - // bad - const value = 0 ?? 'default'; - // returns 0, not 'default' - - // bad - const value = '' ?? 'default'; - // returns '', not 'default' + // good + const value = '' ?? 'default'; // '', not 'default' // good - const value = null ?? 'default'; - // returns 'default' + const value = null ?? 'default'; // 'default' // good const user = { name: 'John', age: null }; - const age = user.age ?? 18; - // returns 18 + const age = user.age ?? 18; // 18 + + // good + const user = { + name: 'John', + }; + const age = user.age ?? 18; // 18 + + // good + const user = { + name: 'John', + age: 0 + }; + const age = user.age ?? 18; // 0 + const defaultAge = user.age || 18 // 18 ``` **[⬆ back to top](#table-of-contents)** @@ -2455,11 +2471,11 @@ Other Style Guides ```javascript // bad - const active = true; // is current tab + const isActive = true; // is current tab // good // is current tab - const active = true; + const isActive = true; // bad function getType() { @@ -2688,10 +2704,10 @@ Other Style Guides // good $('#items') .find('.selected') - .highlight() - .end() + .highlight() + .end() .find('.open') - .updateCount(); + .updateCount(); // bad const leds = stage.selectAll('.led').data(data).enter().append('svg:svg').classed('led', true) @@ -2700,14 +2716,16 @@ Other Style Guides .call(tron.led); // good - const leds = stage.selectAll('.led') - .data(data) - .enter().append('svg:svg') - .classed('led', true) - .attr('width', (radius + margin) * 2) + const leds = stage + .selectAll('.led') + .data(data) + .enter() + .append('svg:svg') + .classed('led', true) + .attr('width', (radius + margin) * 2) .append('svg:g') - .attr('transform', `translate(${radius + margin}, ${radius + margin})`) - .call(tron.led); + .attr('transform', `translate(${radius + margin}, ${radius + margin})`) + .call(tron.led); // good const leds = stage.selectAll('.led').data(data); @@ -2948,11 +2966,12 @@ Other Style Guides ?.xyzzy; // good - $.ajax({ - method: 'POST', - url: 'https://airbnb.com/', - data: { name: 'John' }, - }) + $ + .ajax({ + method: 'POST', + url: 'https://airbnb.com/', + data: { name: 'John' }, + }) .done(() => console.log('Congratulations!')) .fail(() => console.log('You have failed this city.')); ``` @@ -3190,6 +3209,20 @@ Other Style Guides inventorOf, ...heroArgs ); + + // bad + import { + firstVariable, + secondVariable, + thirdVariable + } from './someModule'; + + // good + import { + firstVariable, + secondVariable, + thirdVariable, + } from './someModule'; ``` **[⬆ back to top](#table-of-contents)** @@ -3347,7 +3380,7 @@ Other Style Guides } // good - function query() { + function makeQuery() { // ... } ``` @@ -3743,10 +3776,10 @@ Other Style Guides **[⬆ back to top](#table-of-contents)** -## ECMAScript 5 Compatibility +## ECMAScript 6 Compatibility - - - [27.1](#es5-compat--kangax) Refer to [Kangax](https://twitter.com/kangax/)’s ES5 [compatibility table](https://kangax.github.io/es5-compat-table/). + + - [27.1](#ecmascript-6-compatibility) Refer to [Can I use](https://caniuse.com/es6) for features compatibility **[⬆ back to top](#table-of-contents)** @@ -3860,8 +3893,7 @@ Other Style Guides - [Latest ECMA spec](https://tc39.github.io/ecma262/) - [ExploringJS](https://exploringjs.com/) - - [ES6 Compatibility Table](https://compat-table.github.io/compat-table/es6/) - - [Comprehensive Overview of ES6 Features](https://web.archive.org/web/20240404212626/http://es6-features.org/) + - [Comprehensive Overview of ES6 Features](http://es6-features.org/) - [JavaScript Roadmap](https://roadmap.sh/javascript) **Read This** From 357f3cf7e12442fa8f1b763966f8dac6c90178d8 Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Thu, 7 Mar 2024 22:56:02 +0000 Subject: [PATCH 02/12] Update Readme during review --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0acef98028..049ad4061d 100644 --- a/README.md +++ b/README.md @@ -411,7 +411,7 @@ Other Style Guides ``` - - [4.6](#arrays--mapping) Use [`Array.from`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/from) instead of spread `...` for mapping over iterables like Sets, Maps or NodeLists, because it avoids creating an intermediate array. + - [4.6](#arrays--mapping) Use [`Array.from`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/from) instead of spread `...` for mapping over iterables, because it avoids creating an intermediate array. ```javascript // bad @@ -710,7 +710,7 @@ Other Style Guides // good if (currentUser) { - let test = () => { + const test = () => { console.log('Yup.'); }; } From 54b41126452baad28f39fd0a8b7744d2633be258 Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Thu, 7 Mar 2024 23:56:05 +0000 Subject: [PATCH 03/12] Readme update during review --- README.md | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 049ad4061d..3de769f6aa 100644 --- a/README.md +++ b/README.md @@ -738,13 +738,13 @@ Other Style Guides ```javascript // bad - function concatenateAllStrings() { + function concatenateAll() { const args = Array.prototype.slice.call(arguments); return args.join(''); } // good - function concatenateAllStrings(...args) { + function concatenateAll(...args) { return args.join(''); } ``` @@ -852,11 +852,6 @@ Other Style Guides function f2(obj) { const key = Object.prototype.hasOwnProperty.call(obj, 'key') ? obj.key : 1; } - - // best - function f2(obj) { - const key = Object.hasOwn(obj, 'key') ? obj.key : 1; - } ``` @@ -1198,7 +1193,8 @@ Other Style Guides const luke = new Jedi(); - luke.jump().setHeight(20); + luke.jump() + .setHeight(20); ``` @@ -1329,7 +1325,7 @@ Other Style Guides ``` - - [10.2](#modules--no-wildcard) Do not use wildcard imports unless you have multiple named exports and want to import all of them as single object. + - [10.2](#modules--no-wildcard) Do not use wildcard imports. > Why? This makes sure you have a single default export. @@ -1791,6 +1787,7 @@ Other Style Guides ```javascript // bad + const array = [1, 2, 3]; let num = 1; num++; @@ -1807,6 +1804,7 @@ Other Style Guides } // good + const array = [1, 2, 3]; let num = 1; num += 1; @@ -1846,6 +1844,7 @@ Other Style Guides ```javascript // bad + const some_unused_var = 42; // Write-only variables are not considered as used. @@ -1862,6 +1861,7 @@ Other Style Guides } // good + function getXPlusY(x, y) { return x + y; } @@ -2165,7 +2165,7 @@ Other Style Guides const foo = a ? a : b; const bar = c ? true : false; const baz = c ? false : true; - const quux = (a !== undefined && a !== null) ? a : b; + const quux = a != null ? a : b; // good const foo = a || b; @@ -2966,12 +2966,11 @@ Other Style Guides ?.xyzzy; // good - $ - .ajax({ - method: 'POST', - url: 'https://airbnb.com/', - data: { name: 'John' }, - }) + $.ajax({ + method: 'POST', + url: 'https://airbnb.com/', + data: { name: 'John' }, + }) .done(() => console.log('Congratulations!')) .fail(() => console.log('You have failed this city.')); ``` From f75681a086c9cbbbe412acc27fa00ac264bf1d36 Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Fri, 8 Mar 2024 09:25:06 +0000 Subject: [PATCH 04/12] Fix link for ES5 features compatibility --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3de769f6aa..043ce80035 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ Other Style Guides 1. [Accessors](#accessors) 1. [Events](#events) 1. [jQuery](#jquery) - 1. [ECMAScript 6 Compatibility](#ecmascript-6-compatibility) + 1. [ECMAScript 5 Compatibility](#ecmascript-5-compatibility) 1. [ECMAScript 6+ (ES 2015+) Styles](#ecmascript-6-es-2015-styles) 1. [Standard Library](#standard-library) 1. [Testing](#testing) @@ -3777,8 +3777,8 @@ Other Style Guides ## ECMAScript 6 Compatibility - - - [27.1](#ecmascript-6-compatibility) Refer to [Can I use](https://caniuse.com/es6) for features compatibility + + - [27.1](#ecmascript-5-compatibility) Refer to the [ES5 compatibility table](http://compat-table.github.io/compat-table/es5/) for features compatibility **[⬆ back to top](#table-of-contents)** From 1ef3333f9da306991293881cf47dee172d457dc6 Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Fri, 8 Mar 2024 09:29:28 +0000 Subject: [PATCH 05/12] Add link to ES6 compat features --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 043ce80035..2d6a16a38c 100644 --- a/README.md +++ b/README.md @@ -3778,7 +3778,7 @@ Other Style Guides ## ECMAScript 6 Compatibility - - [27.1](#ecmascript-5-compatibility) Refer to the [ES5 compatibility table](http://compat-table.github.io/compat-table/es5/) for features compatibility + - [27.1](#ecmascript-5-compatibility) Refer to the [ES5 compatibility table](https://compat-table.github.io/compat-table/es5/) for features compatibility **[⬆ back to top](#table-of-contents)** @@ -3892,6 +3892,7 @@ Other Style Guides - [Latest ECMA spec](https://tc39.github.io/ecma262/) - [ExploringJS](https://exploringjs.com/) + - [ES6 Compatibility Table](https://compat-table.github.io/compat-table/es6/) - [Comprehensive Overview of ES6 Features](http://es6-features.org/) - [JavaScript Roadmap](https://roadmap.sh/javascript) From 95c7d2ddf4271caa01583d6916dea9c52004e70e Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Sat, 9 Mar 2024 10:43:55 +0000 Subject: [PATCH 06/12] Update Readme according to discussion --- README.md | 57 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 2d6a16a38c..ededb3c888 100644 --- a/README.md +++ b/README.md @@ -708,6 +708,14 @@ Other Style Guides } } + // good + let test; // if you are planning to reassign value + if (currentUser) { + test = () => { + console.log('Yup.'); + }; + } + // good if (currentUser) { const test = () => { @@ -1478,7 +1486,7 @@ Other Style Guides ## Iterators and Generators - - [11.1](#iterators--nope) Don’t use iterators. Prefer JavaScript’s higher-order functions instead of loops like `for`, `for-in` or `for-of`. eslint: [`no-iterator`](https://eslint.org/docs/rules/no-iterator) [`no-restricted-syntax`](https://eslint.org/docs/rules/no-restricted-syntax) + - [11.1](#iterators--nope) Don’t use iterators. Prefer JavaScript’s higher-order functions instead of loops like `for-in` or `for-of`. eslint: [`no-iterator`](https://eslint.org/docs/rules/no-iterator) [`no-restricted-syntax`](https://eslint.org/docs/rules/no-restricted-syntax) > Why? This enforces our immutable rule. Dealing with pure functions that return values is easier to reason about than side effects. @@ -1639,9 +1647,7 @@ Other Style Guides ## Variables - - [13.1](#variables--const) Always use `const` or `let` to declare variables. Not doing so will result in global variables in case strict mode is disabled. We want to avoid polluting the global namespace. Captain Planet warned us of that. eslint: [`no-undef`](https://eslint.org/docs/rules/no-undef) [`prefer-const`](https://eslint.org/docs/rules/prefer-const) - - > Note: The entire contents of JavaScript modules are automatically in [strict mode](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode) and therefore usage of the undeclared variables will not lead to creation of the global variables + - [13.1](#variables--const) Always use `const` or `let` to declare variables. Not doing so will result in global variables. We want to avoid polluting the global namespace. Captain Planet warned us of that. eslint: [`no-undef`](https://eslint.org/docs/rules/no-undef) [`prefer-const`](https://eslint.org/docs/rules/prefer-const) ```javascript // bad @@ -1750,7 +1756,7 @@ Other Style Guides - [13.5](#variables--no-chain-assignment) Don’t chain variable assignments. eslint: [`no-multi-assign`](https://eslint.org/docs/rules/no-multi-assign) - > Why? Chaining variable assignments creates implicit global variables in case [strict mode](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode) is disabled. + > Why? Chaining variable assignments creates implicit global variables. ```javascript // bad @@ -2103,25 +2109,30 @@ Other Style Guides const x = 2; // SyntaxError: Identifier 'x' has already been declared break; case 3: + // Will be available in entire switch block function f() { // ... } break; default: + // Will be available in entire switch block class C {} } // good switch (foo) { case 1: { + // Will be available only in the case 1 block let x = 1; break; } case 2: { + // Will be available only in the case 2 block const x = 2; // No SyntaxError break; } case 3: { + // Will be available only in the case 3 block function f() { // ... } @@ -2130,7 +2141,8 @@ Other Style Guides case 4: bar(); break; - default: { + default: { + // Will be available only in the default block class C {} } } @@ -2217,7 +2229,10 @@ Other Style Guides > Why? It provides precision by distinguishing null/undefined from other falsy values, enhancing code clarity and predictability. ```javascript - // good + // bad + const value = 0 ?? 'default'; // 0, not 'default' + + // bad const value = '' ?? 'default'; // '', not 'default' // good @@ -2242,7 +2257,7 @@ Other Style Guides age: 0 }; const age = user.age ?? 18; // 0 - const defaultAge = user.age || 18 // 18 + const anotherAge = user.age || 18 // 18 ``` **[⬆ back to top](#table-of-contents)** @@ -2471,7 +2486,7 @@ Other Style Guides ```javascript // bad - const isActive = true; // is current tab + const active = true; // is current tab // good // is current tab @@ -2704,10 +2719,10 @@ Other Style Guides // good $('#items') .find('.selected') - .highlight() - .end() + .highlight() + .end() .find('.open') - .updateCount(); + .updateCount(); // bad const leds = stage.selectAll('.led').data(data).enter().append('svg:svg').classed('led', true) @@ -2716,16 +2731,14 @@ Other Style Guides .call(tron.led); // good - const leds = stage - .selectAll('.led') - .data(data) - .enter() - .append('svg:svg') - .classed('led', true) - .attr('width', (radius + margin) * 2) + const leds = stage.selectAll('.led') + .data(data) + .enter().append('svg:svg') + .classed('led', true) + .attr('width', (radius + margin) * 2) .append('svg:g') - .attr('transform', `translate(${radius + margin}, ${radius + margin})`) - .call(tron.led); + .attr('transform', `translate(${radius + margin}, ${radius + margin})`) + .call(tron.led); // good const leds = stage.selectAll('.led').data(data); @@ -3379,7 +3392,7 @@ Other Style Guides } // good - function makeQuery() { + function query() { // ... } ``` From 14fa2217f5172a1cf8b3bf4bc329d44a79a192bf Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Sat, 9 Mar 2024 22:23:01 +0000 Subject: [PATCH 07/12] Reverted anchor link for es5-compat section --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ededb3c888..084494209d 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ Other Style Guides 1. [Accessors](#accessors) 1. [Events](#events) 1. [jQuery](#jquery) - 1. [ECMAScript 5 Compatibility](#ecmascript-5-compatibility) + 1. [ECMAScript 5 Compatibility](#es5-compat--kangax) 1. [ECMAScript 6+ (ES 2015+) Styles](#ecmascript-6-es-2015-styles) 1. [Standard Library](#standard-library) 1. [Testing](#testing) @@ -709,7 +709,7 @@ Other Style Guides } // good - let test; // if you are planning to reassign value + let test; // if you are planning to reassign value if (currentUser) { test = () => { console.log('Yup.'); @@ -2141,7 +2141,7 @@ Other Style Guides case 4: bar(); break; - default: { + default: { // Will be available only in the default block class C {} } @@ -3790,8 +3790,8 @@ Other Style Guides ## ECMAScript 6 Compatibility - - - [27.1](#ecmascript-5-compatibility) Refer to the [ES5 compatibility table](https://compat-table.github.io/compat-table/es5/) for features compatibility + + - [27.1](#es5-compat--kangax) Refer to the [ES5 compatibility table](https://compat-table.github.io/compat-table/es5/) for features compatibility **[⬆ back to top](#table-of-contents)** From 9c877f3c36d78cef81380bdc1c30b880286bc89a Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk <43352618+bstashchuk@users.noreply.github.com> Date: Sun, 10 Mar 2024 09:37:18 +0000 Subject: [PATCH 08/12] Revert back section title for ES5 Compat Co-authored-by: Jordan Harband --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 084494209d..7327a565e3 100644 --- a/README.md +++ b/README.md @@ -3788,7 +3788,7 @@ Other Style Guides **[⬆ back to top](#table-of-contents)** -## ECMAScript 6 Compatibility +## ECMAScript 5 Compatibility - [27.1](#es5-compat--kangax) Refer to the [ES5 compatibility table](https://compat-table.github.io/compat-table/es5/) for features compatibility From 396251f2cd3e62c3040c9fa28a73c7dc28cb50e7 Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk <43352618+bstashchuk@users.noreply.github.com> Date: Sun, 10 Mar 2024 09:56:40 +0000 Subject: [PATCH 09/12] Update README.md Co-authored-by: Jordan Harband --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7327a565e3..efab959f3a 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ Other Style Guides 1. [Accessors](#accessors) 1. [Events](#events) 1. [jQuery](#jquery) - 1. [ECMAScript 5 Compatibility](#es5-compat--kangax) + 1. [ECMAScript 5 Compatibility](#ecmascript-5-compatibility) 1. [ECMAScript 6+ (ES 2015+) Styles](#ecmascript-6-es-2015-styles) 1. [Standard Library](#standard-library) 1. [Testing](#testing) From 3777f60bf042e6bfd16a460b5ff4b47f05dea7f3 Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk <43352618+bstashchuk@users.noreply.github.com> Date: Wed, 12 Mar 2025 22:23:41 +0000 Subject: [PATCH 10/12] Update README.md Co-authored-by: Jordan Harband --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index efab959f3a..98a68f8af7 100644 --- a/README.md +++ b/README.md @@ -1659,7 +1659,7 @@ Other Style Guides } foo() - console.log(bar) // 10 + console.log(bar); // 10 // good const superPower = new SuperPower(); From 7f0d973f99171f47e3e1211759b9127d57b95de3 Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk <43352618+bstashchuk@users.noreply.github.com> Date: Wed, 12 Mar 2025 22:23:59 +0000 Subject: [PATCH 11/12] Update README.md Co-authored-by: Jordan Harband --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 98a68f8af7..960213d5d4 100644 --- a/README.md +++ b/README.md @@ -1655,7 +1655,7 @@ Other Style Guides // bad function foo() { - bar = 10 // bar will appear in the global scope + bar = 10; // bar will appear in the global scope } foo() From fb991e3045e3cf4d372084ba28d9c043c12e5773 Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk <43352618+bstashchuk@users.noreply.github.com> Date: Wed, 12 Mar 2025 22:24:35 +0000 Subject: [PATCH 12/12] Update README.md Co-authored-by: Jordan Harband --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 960213d5d4..2dfa966a08 100644 --- a/README.md +++ b/README.md @@ -1658,7 +1658,7 @@ Other Style Guides bar = 10; // bar will appear in the global scope } - foo() + foo(); console.log(bar); // 10 // good