JavaScript Arrow Function Exercises and Practice Questions
JavaScript Arrow Function Exercises and Practice Questions
Practice Questions
You will find practice questions related to the arrow function in JavaScript on this page. Solving
these exercise questions will improve your understanding of different ways of using arrow
functions in JavaScript.
If you are interested in solving questions related to the javascript array and object destructuring,
then visit the following links:
Q1 Write an arrow function expression called greet(). It should accept a single argument
representing a person's name. It should return a greeting string as shown below:
Solution
Q2 Write an arrow function named arrayAverage that accepts an array of numbers and returns
the average of those numbers.
Solution
function counterFunc(counter) {
if (counter > 100) {
counter = 0;
}else {
counter++;
}
return counter;
}
Solution
return counter;
}
Q5 Write an arrow function named dashTwixt2Evens that accepts a number and inserts dashes
(-) between two even numbers.
Expected Output
dashTwixt2Evens(225468) //"2-254-6-8"
dashTwixt2Evens(8675309) //"8-675309"
Solution
Q6 Write an arrow function named sumEvens that accepts an array of numbers and returns the
sum of the even numbers in the array. Use a for...of statement.
Solution
Q7 Square and sum the elements of this array using arrow functions and in 1 line of code. Then
find the average of the array.
Solution
Solution
let list=[1,2,3,4,5,6,7,8];
Use the map() function with arrow notation => to multiply each number by 10 and return the
result.
Solution
let list=[1,2,3,4,5,6,7,8];
function printOnly(){
console.log("printing");
}
Solution
Q11 Rewrite the following three functions as arrow functions. Make sure to assign them to a
const identifier.
function doubleNumber(number) {
return number * 2;
}
function getEvenNumbers(array) {
let evenNumbers = [];
for (let i of array) {
if (i % 2 === 0) {
evenNumbers.push(i);
}
}
return evenNumbers;
}
Solution
function isEven(num){
return num%2 === 0;
}
Solution
Q13 Q13 Write an arrow function named greetByFullName, which accepts two strings
(firstName and lastName) and returns a personalized greeting that spans two output lines. Use a
template literal to solve this exercise.
alert(greetByFullName("Jille", "Bonnefemme"));
Expected Output
Solution
Q14 Write an arrow function that will take one parameter weight in Kg. This arrow function will
convert Kg to Lbs. Formula is kg*2.2
Solution
Q15 Q15 Write an arrow function named arrMax that accepts an array of numbers and returns
the largest number in the array. Use the Array.forEach method.
Solution