-
Notifications
You must be signed in to change notification settings - Fork 26.7k
Update README file - Extend explanations, fix formatting mistakes and expand examples #2938
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
bstashchuk
wants to merge
13
commits into
airbnb:master
Choose a base branch
from
bstashchuk:update-readme
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a8dab70
Update README file
bstashchuk 357f3cf
Update Readme during review
bstashchuk 54b4112
Readme update during review
bstashchuk f75681a
Fix link for ES5 features compatibility
bstashchuk 1ef3333
Add link to ES6 compat features
bstashchuk 95c7d2d
Update Readme according to discussion
bstashchuk 14fa221
Reverted anchor link for es5-compat section
bstashchuk 9c877f3
Revert back section title for ES5 Compat
bstashchuk 396251f
Update README.md
bstashchuk 3777f60
Update README.md
bstashchuk 7f0d973
Update README.md
bstashchuk fb991e3
Update README.md
bstashchuk 9e54d97
Merge branch 'master' into update-readme
bstashchuk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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]; | ||
| } | ||
|
|
||
|
|
@@ -710,12 +709,19 @@ Other Style Guides | |
| } | ||
|
|
||
| // good | ||
| let test; | ||
| let test; // if you are planning to reassign value | ||
| if (currentUser) { | ||
| test = () => { | ||
| console.log('Yup.'); | ||
| }; | ||
| } | ||
|
|
||
| // good | ||
| if (currentUser) { | ||
| const test = () => { | ||
|
bstashchuk marked this conversation as resolved.
|
||
| console.log('Yup.'); | ||
| }; | ||
| } | ||
| ``` | ||
|
|
||
| <a name="functions--arguments-shadow"></a><a name="7.5"></a> | ||
|
|
@@ -1031,9 +1037,9 @@ Other Style Guides | |
| ``` | ||
|
|
||
| <a name="arrows--one-arg-parens"></a><a name="8.4"></a> | ||
| - [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. | ||
|
ljharb marked this conversation as resolved.
|
||
|
|
||
| ```javascript | ||
| // bad | ||
|
|
@@ -1129,6 +1135,7 @@ Other Style Guides | |
| constructor(contents = []) { | ||
| this.queue = [...contents]; | ||
| } | ||
|
|
||
| pop() { | ||
| const value = this.queue[0]; | ||
| this.queue.splice(0, 1); | ||
|
|
@@ -1493,18 +1500,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 | ||
|
Comment on lines
+1503
to
+1514
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these are implicit. |
||
|
|
||
| // bad | ||
| const increasedByOne = []; | ||
|
|
@@ -1646,6 +1653,14 @@ Other Style Guides | |
| // bad | ||
| superPower = new SuperPower(); | ||
|
|
||
| // bad | ||
| function foo() { | ||
| bar = 10 // bar will appear in the global scope | ||
|
bstashchuk marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| foo() | ||
|
bstashchuk marked this conversation as resolved.
Outdated
|
||
| console.log(bar) // 10 | ||
|
bstashchuk marked this conversation as resolved.
Outdated
|
||
|
|
||
| // good | ||
| const superPower = new SuperPower(); | ||
| ``` | ||
|
|
@@ -2091,28 +2106,33 @@ Other Style Guides | |
| let x = 1; | ||
| break; | ||
| case 2: | ||
| const y = 2; | ||
| const x = 2; // SyntaxError: Identifier 'x' has already been declared | ||
|
bstashchuk marked this conversation as resolved.
bstashchuk marked this conversation as resolved.
|
||
| 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: { | ||
| const y = 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() { | ||
| // ... | ||
| } | ||
|
|
@@ -2122,6 +2142,7 @@ Other Style Guides | |
| bar(); | ||
| break; | ||
| default: { | ||
| // Will be available only in the default block | ||
| class C {} | ||
| } | ||
| } | ||
|
|
@@ -2209,24 +2230,34 @@ Other Style Guides | |
|
|
||
| ```javascript | ||
| // bad | ||
| const value = 0 ?? 'default'; | ||
| // returns 0, not 'default' | ||
| const value = 0 ?? 'default'; // 0, not 'default' | ||
|
|
||
| // bad | ||
| const value = '' ?? 'default'; | ||
| // returns '', not 'default' | ||
|
bstashchuk marked this conversation as resolved.
|
||
| 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 anotherAge = user.age || 18 // 18 | ||
| ``` | ||
|
|
||
| **[⬆ back to top](#table-of-contents)** | ||
|
|
@@ -2459,7 +2490,7 @@ Other Style Guides | |
|
|
||
| // good | ||
| // is current tab | ||
| const active = true; | ||
| const isActive = true; | ||
|
|
||
| // bad | ||
| function getType() { | ||
|
|
@@ -3190,6 +3221,20 @@ Other Style Guides | |
| inventorOf, | ||
| ...heroArgs | ||
| ); | ||
|
|
||
| // bad | ||
| import { | ||
| firstVariable, | ||
| secondVariable, | ||
| thirdVariable | ||
| } from './someModule'; | ||
|
|
||
| // good | ||
| import { | ||
| firstVariable, | ||
| secondVariable, | ||
| thirdVariable, | ||
| } from './someModule'; | ||
|
ljharb marked this conversation as resolved.
|
||
| ``` | ||
|
|
||
| **[⬆ back to top](#table-of-contents)** | ||
|
|
@@ -3746,7 +3791,7 @@ Other Style Guides | |
| ## ECMAScript 5 Compatibility | ||
|
|
||
| <a name="es5-compat--kangax"></a><a name="26.1"></a> | ||
| - [27.1](#es5-compat--kangax) Refer to [Kangax](https://twitter.com/kangax/)’s ES5 [compatibility table](https://kangax.github.io/es5-compat-table/). | ||
|
bstashchuk marked this conversation as resolved.
Outdated
|
||
| - [27.1](#es5-compat--kangax) Refer to the [ES5 compatibility table](https://compat-table.github.io/compat-table/es5/) for features compatibility | ||
|
|
||
|
bstashchuk marked this conversation as resolved.
|
||
| **[⬆ back to top](#table-of-contents)** | ||
|
|
||
|
|
@@ -3861,7 +3906,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/) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please revert this; http://es6-features.org is now some kind of russian ad site. |
||
| - [JavaScript Roadmap](https://roadmap.sh/javascript) | ||
|
|
||
| **Read This** | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.