![]() |
The arguments and Rest Parameters is crucial for the writing efficient and modern JavaScript code. The arguments object has been traditionally used in functions to the access the parameters passed to them. However, with the introduction of the ES6 Rest Parameters provide the more readable and flexible way to the handle function arguments. These are the following topics that we are going to discuss: Table of Content What is argument Object?The arguments object is an array-like object accessible inside functions that contain the values of the arguments passed to that function. It is not an array but it can be converted into the one. Syntax:function example() { Example: It demonstrates arguments contains all the arguments passed to the sum function.
Output 10 What are Rest Parameters?The Rest Parameters introduced in ES6 allow to the represent an indefinite number of the arguments as an array. This provides a more convenient and cleaner syntax compared to the arguments object. Syntax:function example(...args) { Example: The code demonstrates a function `sum` using rest parameters to compute the sum of any number of arguments passed to it.
Output 10 Difference Between Argument Object and Rest Parameters
|
Reffered: https://www.geeksforgeeks.org
JavaScript |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 19 |