I love learning something new that’s core to the JavaScript language syntax! A code exercise I completed today did just that.
Via this comma, items is returned.
const removeItemAtBottom = (items) => (items.shift(), items);
const cards = [1, 2, 3, 4, 5];
removeItemAtBottom(cards); // [ 2, 3, 4, 5 ]
This helps us around the fact that shift() returns the removed item, 1,
rather than the list of items that we modified.
It works outside a function as well:
const person = ('nobody', false, 'jake');
person; // 'jake'
I’ll be looking for a use-case for this in the future.
- Comma operator – MDN