-1

For example:

What does

this.head = this.tail = new Node(value)

do? How does javascript interpret this line?

Is this the same as writing:

this.head = new Node(value);
this.tail = new Node(value);

If so, is there any limitation on when and where this one line approach can be used?

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • `a = b = c` is equal to `a = (b = c)`, see [operator precedence](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence) – ASDFGerte Sep 21 '21 at 21:05
  • 1
    Does this answer your question? [Multiple left-hand assignment with JavaScript](https://stackoverflow.com/questions/1758576/multiple-left-hand-assignment-with-javascript) – Ervin Szilagyi Sep 21 '21 at 21:05

1 Answers1

0

No, it's assigning the same value to both variables. So it's equivalent to

this.tail = new Node(value);
this.head = this.tail;

Your equivalence would create 2 different Node objects, but there's only 1.

Barmar
  • 741,623
  • 53
  • 500
  • 612