PASSWORD RESET

Your destination for complete Tech news

What is arrow function in Javascript?

274 0
< 1 min read

An arrow function is a shorter syntax for defining a function in JavaScript. It was introduced in ECMAScript 6 (also known as ECMAScript 2015) and is now widely supported in modern browsers and environments.

Here is an example of a traditional function definition:

function add(x, y) {
  return x + y;
}

Here is the same function defined using an arrow function:

const add = (x, y) => {
  return x + y;
};

You can also define a function with a single expression using the concise body syntax. In this case, the return statement is implicit, and you can omit the curly braces:

const add = (x, y) => x + y;

Arrow functions have a few notable differences from traditional function declarations:

  • They do not have their own this, arguments, super, or new.target.
  • They cannot be used as constructors.
  • They do not have a prototype property.

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.