Arrow Function and "this" keyword
Shubham_Baghel
Posted on March 9, 2020
Arrow Function
Arrow function expression are a more concise syntax for writing function expressions although without its own bindings to the this, arguments, super, or new.target keywords. They utilize a new token, =>, that looks like a fat arrow. Arrow functions are anonymous and change the way this binds in functions.
Code samples:
Following are the examples about arrow function
Examples:
In case if you have one argument only,then parentheses around parameters can be avoided,making that even shorter ans simpler syntactically.
this keyword
Execution context for an execution is global — which means if a code is being executed as part of a simple function call, then this refers to a global object.
Arrow functions do not bind their own this, instead, they inherit the one from the parent scope, which is called "lexical scoping".In code with multiple nested functions, it can be difficult to keep track of and remember to bind the correct this context. In ES5, you can use workarounds like the .bind method.Because arrow functions allow you to retain the scope of the caller inside the function, you don’t need to use bind.
Posted on March 9, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.