3 ms·
why bother with the distinction between one * and two *? in javascript the … operator neatly does both
by swyx 4y ago
why bother with the distinction between one * and two *?
in javascript the … operator neatly does both
- zdragnar 4y agoTechnically, `...` acts as either the spread or the rest operator, depending on the location. I recall there was an initial impression of intimidation among people who were familiar with ES5 syntax when trying to adopt to these new features because of this. On the other hand, I'm fairly certain that having to visually disambiguate between `` and `*` and remembering which did what would have gotten a similar reaction.
- gdwatson 4y agoPython has keyword arguments to functions. In that context, a single star packs or unpacks a list of positional arguments and a double star packs or unpacks a dictionary of keyword arguments.
- gpderetta 4y agoTo complete the description, dictionaries are iterable by key only by default[1], so *dict would be ambiguous if it could splat both. [1] a misfeature, IMNSHO.