0% found this document useful (0 votes)
2 views

Array function

Arrow functions in JavaScript, introduced in ES6, provide a concise syntax for writing functions without names, using the '=>' syntax. They can take zero, one, or multiple parameters and return expressions more cleanly than traditional function expressions. An example is provided that demonstrates the creation of a simple arrow function to add two numbers.

Uploaded by

shubrattporwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Array function

Arrow functions in JavaScript, introduced in ES6, provide a concise syntax for writing functions without names, using the '=>' syntax. They can take zero, one, or multiple parameters and return expressions more cleanly than traditional function expressions. An example is provided that demonstrates the creation of a simple arrow function to add two numbers.

Uploaded by

shubrattporwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Arrow Function in JavaScript

What is arrow function in JavaScript?


Arrow function is one of the features introduced in ES6 for writing better
javascript.

Arrow function is similar to a function expression, but it does not have a


name. It is written as a function expression with parenthesis.

The function expression is followed by an arrow ( =>). The arrow function


expression is followed by an expression, which is returned by the arrow
function.

let message = (name) => { return `Hello ${name}`; }

Arrow function in javascript is an alternative way to write a function with


shorter and cleaner syntax than a regular function.

An arrow function is also called the fat arrow function.

Syntax of arrow function


The syntax of the arrow function is similar to the syntax of a function
expression, except that it does not have a name.

() => { ... } // no parameter


param1 => { ... } // one parameter
(param1, param2) => { ... } // multiple parameters
The above syntax shows a function with no parameters, a function with
one parameter, and a function with multiple parameters.

Example of arrow function


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Arrow function - javascript</title>
</head>
<body>
<h2>Creating simple arrow function in javascript.</h2>

<script>
const add = (a, b) => { return a + b };
document.write(add(1, 2));
</script>
</body>
</html>

You might also like