javascript

Arrow Functions


 

Arrow functions are a concise syntax for writing anonymous functions in JavaScript, introduced in ECMAScript 6. They allow you to define functions using a shorter syntax, omitting the function ‘keyword’ and providing an implicit return for single expressions.

Arrow functions inherit the ‘this’ context from the surrounding code, making them particularly useful for maintaining lexical scoping. However, they lack an ‘arguments’  object and cannot be used as constructors, limiting their versatility compared to traditional functions.

 

Example: without Arrow Function
 

function arrFun(){
	console.log("Hello Coders!");
}
arrFun();

 

Example: With Arrow Fuction

const arrFun = () => {
	console.log( "Hello Coders!" );
}

arrFun();