Is there a name for this? Here’s an example of what I’m trying to say:
var i = 0;
var j = 0;
i = j = 1;
So obviously both i and j are set to 1. But is there a name for this practice? Also, in terms of good coding standards, is this type of thing generally avoided? Can I also get an example or explanation of why it is/isn’t good practice?
As Daniel said, it’s called chained assignment. It’s generally avoided, because for some values (such as objects), the line
i = j = _something_creates a reference fromitoj. If you later changej, thenialso changes.See this jsFiddle demo for an example: http://jsfiddle.net/jackwanders/a2XJw/1/
If you don’t know what
iandjare going to be, you could run into problems