question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Chaining variable assignments Example

See original GitHub issue

There 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:closed
  • Created 6 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ljharbcommented, Jun 16, 2017

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?

1reaction
ljharbcommented, Jun 16, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found