Follow The New Tutorial updates on WhatsApp, Telegram or YouTube.

JavaScript – Arguments Binding in Arrow Function

Regular functions have arguments binding. When you pass arguments to a regular function, you can access them using the arguments keyword as shown in below example.

let x = function () {
    console.log(arguments);
}
x(4,6,7); // Arguments [4, 6, 7]

Arrow functions do not have arguments binding.

When you try to access an argument using the arrow function, it will give an error as shown in below example.

let x = () => {
    console.log(arguments);
}

x(4,6,7); 
// ReferenceError: Can't find variable: arguments

To solve this issue, you can use the spread syntax as shown in below example.

let x = (...n) => {
    console.log(n);
}

x(4,6,7); // [4, 6, 7]