The Beauty Of Arrow Functions In JavaScript

An arrow function expression has a shorter syntax compared to function expressions.

It does not have its own this, arguments, super, or new operator.

If the function has only one statement, and the statement returns a value, the brackets and the return keyword can be removed.

* * *

hello = () => “Hello World! “;

Until arrow functions, every new function defined its own this value.

An arrow function does not have its own this; the this value of the enclosing execution context is used.

* * *

function Person() {

this.age = 0;

setInterval( () => {

this .age++; // |this| properly refers to the

person object

}, 1000) ;

}

var p = new Person ();

Leave a Reply

Your email address will not be published. Required fields are marked *