Arrow Function Flashcards

1
Q

What is an Arrow Function ?

A

Great for a quick one-line functions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Symbol for Arrow Function ?

A

=>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Coding Challenge ( Arrow Function )

The world population is 7900 million people. Create a function declaration called ‘percentageOfWorld3’ which receives a ‘population’ value, and returns the percentage of the world population that the given population.
For example, China has 1441 million people, so it’s about 18.2% of the world population

Call ‘percentageOfWorld3’ for 3 populations of countries of your choice, store the results into variables, and log them to the console

A
const percentageOfWorld3 = population => (population / 7900) * 100;
const percPortugal3 = percentageOfWorld3(10);
const percChina3 = percentageOfWorld3(1441);
const percUSA3 = percentageOfWorld3(332);
console.log(percPortugal3, percChina3, percUSA3);

Output :- 0.12658227848101267 18.240506329113924 4.2025316455696204

How well did you know this?
1
Not at all
2
3
4
5
Perfectly