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.
-
LIVE
I_Came_With_Fire_Podcast
13 hours agoNO EPSTEIN FILES | AI Marco Rubio | China Attacks Germany | Cloud Seeding in TX & NM?
274 watching -
3:14:05
Geeks + Gamers
4 hours agoGeeks + Gamers Play- MARIO KART WORLD
28.6K -
LIVE
Alex Zedra
3 hours agoLIVE! Scary Games tn!
296 watching -
47:26
Friday Beers
7 hours ago $1.43 earnedWe Drank 12 Beers & Found the Zodiac Killer
32.1K2 -
1:02:33
Mike Rowe
1 day agoCan We Fix The American Diet? | Jillian Michaels #441 | The Way I Heard It
20K17 -
1:08:23
VapinGamers
4 hours ago $0.95 earnedDune Awakening - Community Spice and Everything Nice Game Night - !rumbot !music
15.5K -
3:32:02
Fragniac
5 hours ago🔴 MAKE FPS GREAT AGAIN❗
13.8K -
3:05:48
RCAM
4 hours ago $0.79 earnedMarvel Rivals | Expedition 33 | Gaming on Rumble | @SELFMADEGGS
12.3K3 -
Razeo
4 hours agoEp 3 Batman Arkham City 1st playthrough – The Bat signal calls, Gotham’s Hero Rises Again!
9.48K1 -
8:50:56
Dr Disrespect
14 hours ago🔴LIVE - DR DISRESPECT vs TARKOV - NEW HARDCORE WIPE (DAY 1)
148K9