Premium Only Content
Learn Functions in JavaScript | Day 34 | Arrow And Return Keyword | Web development course 2023
rrow functions are a concise way to write JavaScript functions. They were introduced in ES6 and offer several advantages over traditional function declarations, including:
Conciseness: They are written using shorter syntax.
Lexical this binding: They capture the this value of the enclosing scope.
Implicit return: They can implicitly return the value of the expression in their body.
Here's the basic syntax of an arrow function:
JavaScript
(parameters) => expression
Use code with caution. Learn more
The parameters and the expression are separated by an arrow (=>). If the function has no parameters, you can use empty parentheses.
Return Keyword:
The return keyword is used to explicitly return a value from a function. However, in arrow functions with a single expression in their body, the return keyword is implicit. This means you don't need to write it explicitly, and the expression's value will be the function's return value.
Here are some examples:
1. Single expression:
JavaScript
const double = (number) => number * 2;
const result = double(5); // result will be 10
Use code with caution. Learn more
2. Multiple expressions:
JavaScript
const isEven = (number) => {
if (number % 2 === 0) {
return true;
} else {
return false;
}
};
const number = 8;
const isEvenResult = isEven(number); // isEvenResult will be true
Use code with caution. Learn more
3. Implicit return:
JavaScript
const square = number => number ** 2;
const area = square(10); // area will be 100
Use code with caution. Learn more
Key Points:
Arrow functions are concise and have lexical this binding.
In arrow functions with a single expression, the return keyword is implicit.
You can still use the return keyword explicitly in arrow functions with multiple expressions.
-
8:22
Russell Brand
16 hours agoThey want this to happen
198K393 -
2:06:43
Jewels Jones Live ®
1 day ago2025 STARTS WITH A BANG! | A Political Rendezvous - Ep. 104
110K38 -
4:20:41
Viss
15 hours ago🔴LIVE - PUBG Duo Dominance Viss w/ Spartakus
87.1K10 -
10:15:14
MDGgamin
19 hours ago🔴LIVE-Escape From Tarkov - 1st Saturday of 2025!!!! - #RumbleTakeover
69.9K2 -
3:54:19
SpartakusLIVE
15 hours agoPUBG Duos w/ Viss || Tactical Strategy & HARDCORE Gameplay
80.3K1 -
5:54:54
FRENCHY4185
15 hours agoFRENCHY'S BIRTHDAY BASH !!! THE BIG 40 !!!
88.6K3 -
1:23:33
Michael Franzese
23 hours agoThings to look forward to in 2025
106K62 -
3:23:02
I_Came_With_Fire_Podcast
1 day agoDefeating VICTIMHOOD: Advocacy, Resiliency, and Overcoming Abuse
109K20 -
2:00:56
Game On!
1 day ago $10.62 earnedNFL Experts debate if Joe Burrow will make HISTORY in Week 18!
120K16 -
2:07:57
InfiniteWaters(DivingDeep)
4 days agoHOW TO ENTER 2025 LIKE A BOSS!
47.3K1