javascript

Arrow Functions

Arrow functions, also called “fat arrows” were introduced with ES6 as a new syntax for writing Javascript functions.

By utilising a token (=>) that looks like a fat arrow, they are a more concise and elegant way of writing function expressions.

Basic Syntax

//ES5 Way
function myFunc() {
//statements here ...
}

//ES6 Way
myFunc = () => {
//statements here ...
}

Parentheses in ES6 functions are optional when only one parameter is passed.

myFunc = val => {
return val += 1;
}
alert(myFunc(2)); //3

But if no parameters are passed to the function, then parentheses are required.

Recent Posts

How to Create Neumorphism Effect with CSS

Neumorphism design, alternatively termed as "soft UI" or "new skeuomorphism," represents a design trend that…

1 day ago

How to Debug Your JavaScript Code

Debugging JavaScript code can sometimes be challenging, but with the right practices and tools, you…

4 days ago

Service Workers in JavaScript: An In-Depth Guide

Service Workers are one of the core features of modern web applications, offering powerful capabilities…

2 weeks ago

What are Database Driven Websites?

A database-driven website is a dynamic site that utilizes a database to store and manage…

3 weeks ago

How to show Toast Messages in React

Toasts are user interface elements commonly used in software applications, especially in mobile app development…

3 weeks ago

Exploring the Relationship Between JavaScript and Node.js

JavaScript has long been synonymous with frontend web development, powering interactive and dynamic user interfaces…

4 weeks ago