Comma operator vs last element in an array

Viewed 37

Not really a practical question, but say you are using the comma operator in a reduce function like so:

class MyArray extends Array {/* ... */}

const v = new MyArray(55).reduce((a,b) => {
     return a.push(b), a;
},[]);

is that any different than using an array with pop() like so:

 const v = new MyArray(55).reduce((a,b) => {
     return [a.push(b), a].pop();
 },[]);

doesn't seem different, just a way to group operations on one line? I think the only reason this is useful is that the comma operator might get flagged by IDEs and linters as "too fancy", and perhaps rightfully so.

0 Answers
Related