Chaining variable assignments Example
See original GitHub issueThere is an issue with the example mentioned in the following section
13.5 Don’t chain variable assignments.
Accessing the value of a
would throw an Uncaught ReferenceError: a is not defined.
https://github.com/airbnb/javascript#variables–no-chain-assignment
// bad
(function example() {
// JavaScript interprets this as
// let a = ( b = ( c = 1 ) );
// The let keyword only applies to variable a; variables b and c become
// global variables.
let a = b = c = 1;
}());
console.log(a); // undefined
console.log(b); // 1
console.log(c); // 1
``` `
Issue Analytics
- State:
- Created 6 years ago
- Comments:11 (5 by maintainers)
Top Results From Across the Web
In JavaScript, is chained assignment okay? - Stack Overflow
Yes, they're not the same. var a = b = [] is equivalent to var a; b = []; a = b;. Not...
Read more >JavaScript Tutorial => Chaining assignments in var declarations.
Chaining assignments as part of a var declaration will create global variables unintentionally. ... var a = (b = 0);. The correct way...
Read more >chaining variable declarations - Google Groups
The single-line multiple assignment '$a=$b=$c=something' is not consistent across different data types. While it assigns copies of the value for scalars and ...
Read more >python variables assignment and assignment chaining
Python variables assignment operation calling variables and assignment chaining.
Read more >Assignment operator. - Embedded Wizard
In this way a single expression can perform multiple assignments to multiple variables or the assignments can be chained. Following example demonstrates the ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Gotcha.
If you’re interested in making a PR, let’s just change the
undefined
comment to “throws ReferenceError” in all 4 places 😃 that seems easiest. Thoughts?Fair point. I suppose we could add a
let a;
above the IIFE.I think the purpose of the example is clear regardless, but that’s certainly a good tweak.