JavaScript Functions Quiz
Test Yourself
Test your knowledge of JavaScript functions.
This quiz uses the same examples you learned in the tutorial chapters.
Question 1
What is returned in the text variable?
function sayHello() {
return "Hello World";
}
let text = sayHello();
- A. sayHello
- B. Hello World
- C. undefined
Question 2
Which line calls the function?
function test() {
return 5;
}
let x = test;
let y = test();
- A. function test() { }
- B. let x = test;
- C. let y = test();
Question 3
In the function below, what are a and b?
function multiply(a, b) {
return a * b;
}
- A. Arguments
- B. Parameters
- C. Return values
Question 4
What is returned by this function call?
function add(a, b) {
return a + b;
}
add(2, 3) * 10;
- A. 5
- B. 10
- C. 50
Question 5
What value is returned if a function has no return statement?
- A. null
- B. false
- C. undefined
Question 6
Which type of function can be called before it is defined?
- A. Function declaration
- B. Function expression
- C. Arrow function
Question 7
Which arrow function is correct?
- A. const add = (a, b) => return a + b;
- B. const add = a, b => a + b;
- C. const add = (a, b) => a + b;
Question 8
What does this refer to inside an object method?
const person = {
name: "John",
getName: function() {
return this.name;
}
};
- A. The function itself
- B. The global object
- C. The object that owns the method
Question 9
Why does this code not work as expected?
const person = {
name: "John",
greet: () => this.name
};
- A. Arrow functions cannot return values
- B. Arrow functions do not have their own this
- C. The object syntax is wrong
Question 10
What is an IIFE used for?
- A. To delay code execution
- B. To create a private scope
- C. To repeat code automatically
Answers
Question 1
Answer: B.
Explanation: The function returns the string "Hello World".
Question 2
Answer: C.
Explanation: Parentheses () execute the function.
Question 3
Answer: B.
Explanation: Parameters are the names listed in the function definition.
Question 4
Answer: C.
Explanation: The function returns 5, then it is multiplied by 10.
Question 5
Answer: C.
Explanation: Functions without return return undefined.
Question 6
Answer: A.
Explanation: Function declarations are hoisted.
Question 7
Answer: C.
Explanation: Arrow functions return expressions without return when written on one line.
Question 8
Answer: C.
Explanation: In a method, this refers to the owner object.
Answer: C.
Explanation: In a method, this refers to the owner object.
Question 9
Answer: B.
Explanation: Arrow functions inherit this from their surrounding scope.
Question 10
Answer: B.
Explanation: IIFEs were commonly used to avoid global variables.
Quiz Result
If you answered most questions correctly, you have a solid understanding of JavaScript functions.
If not, revisit the chapters and try again.