October 2018
Intermediate to advanced
590 pages
15h 5m
English
In ES5, inside a function body, you can use the arguments object to iterate the parameters of the function. In ES6, you can use rest parameters syntax to define an indefinite number of arguments as an array.
Let's see the following example:
1. // Using arguments in ES52. function workout(exercise1) {3. var todos = Array.prototype.slice.call(arguments, workout.length);4. console.log('Start from ' + exercise1);5. console.log(todos.length + ' more to do');6. }7. // equivalent to rest parameters in ES68. function workout(exercise1, ...todos) {9. console.log('Start from ' + exercise1); // Start from //Treadmill10. console.log(todos.length + ' more to do'); // 2 more to do11. console.log('Args length: ' + workout.length);
Read now
Unlock full access