In todayâs blog, we will learn about Arrow Functions in ReactJS. Let us find out What are Arrow Functions and how they are used in ReactJS.
Contents
The arrow function is one of the features introduced in the ES6 version of javascript. It allows you to create functions in a cleaner way. The arrow function is a compressed and shorter version of the function expression. It requires fewer keystrokes by developers.
An arrow function expression is a compressed alternative to a regular function expression. But it also has some limitations in usage:
// function expression Let X = function (X,Y) { return X * Y } // using arrow function Let X = (X, Y) => X * Y ;
If a function doesnât take any argument, then it should use empty parentheses.
Let greet = () => console.log(âHelloâ); greet();
Note: This works only if the function has only one statement.
Arrow Function With Parameters:
hello = (val) => "Hello " + val; let names = ['John', 'Mac', 'Peter']; let lengths = names.map(name => name.length); console.log(lengths);
This was all about Arrow Function in ReactJS. To learn more about React, follow ReactJS blogs and stay updated. Share the article with your friends, and comment down your doubts or queries.
Happy Coding!
Are you setting up a payroll system for your eCommerce startup? Ensuring compliance with myriad…
In the expansive universe of Laravel development, Blade serves as the stellar templating engine, propelling…
Hello Magento Friends, In this blog, we will discuss about adding quantity increment and decrement…
In this guide, we'll explore how to integrate ChatGPT, an AI-powered chatbot, with a Laravel…
In the world of business, understanding financial metrics is crucial for making informed decisions and…
Welcome to the MageComp Monthly Digest, where we bring you the latest updates, releases, and…