JavaScript features I'd like to remember and use more often
The arguments
object and ...rest
parameters syntax
- Especially useful when you don't know the number of arguments in a function
- Or when destructing an object and you want the remaining properties in a separate object
- Prefer rest parameters when writing ES6
- One advantage of using
...rest
syntax for function arguments is that the result will be an actual array, unlike arguments
, which is an array-like object. The latter doesn't have built-in array methods like .map()
and such.
for...of
loop
- to iterate over values in an iterable.
- don't use
for...in
(Note that it's for a different purpose and can cause unexpected problems, TODO demo these problems)
getters and setters
TODO code example
Use Object.entries()
to get all values in an array.