Difference between normal & arrow function | JavaScript Tutorials in Hindi | Interview Question #26
In JavaScript, there are two types of functions: normal functions and arrow functions.
Syntax:
Normal function syntax uses the function keyword, followed by the function name, parameter list, and function body. Arrow function syntax uses a shorter syntax that omits the function keyword, and instead uses an arrow between the parameter list and function body.
Binding of this:
Normal functions create a new this binding for every function call, based on how the function is called. This can be confusing in some cases, especially when dealing with nested functions and callbacks. Arrow functions, on the other hand, inherit the this binding from their parent scope.
Use of arguments:
Normal functions have access to a special variable called arguments, which is an array-like object that contains all the arguments passed to the function. Arrow functions, on the other hand, do not have access to arguments.
Overall, arrow functions can provide a more concise and clearer syntax, especially for simple functions, while normal functions are still useful for more complex scenarios that require access to arguments or dynamic this binding.