WorksheetsJavaScript Functions Quiz
Total questions: 30
Worksheet time: 15mins
What keyword is used to define a function in JavaScript?
define
func
function
method
Which of the following defines a function expression?
function greet() {}
const greet = function() {};
function = greet() {};
let greet = () => {}
Which function type is not hoisted in JavaScript?
Function declaration
Function expression
Arrow function
Both B and C
What will this code print?
console.log(square(4));
const square = n => n * n;
16
Error
undefined
NaN
Arrow functions were introduced in which version of JavaScript?
ES5
ES6
ES7
ES2019
What is the correct syntax for an arrow function that adds two numbers?
(a, b) => a + b
a, b => { return a + b }
a, b -> a + b
=> (a + b)
What is the output of this function?
Hello
Hello undefined
Hello Guest
Error
Which of the following returns a value from a function?
output
echo
return
What is a higher-order function?
A function that calls itself
A function that takes or returns another function
A function declared inside another
A recursive function
Which of the following is an example of a callback?
Function passed as argument
Function that runs first
Function without parameters
Function with default values
What will this output be?
greet
callback
Hi!
Error
What is printed here?
5
undefined
Error
5 undefined
In JavaScript, this keyword inside an arrow function refers to:
The global object
The function itself
Its parent scope
Always undefined
Which is a valid anonymous function?
function() { console.log('Hello'); }
function sayHi() {}
sayHi = () => {}
var fn = function named() {}
What does this code output?
(function() {
console.log("IIFE executed!");
})();
Nothing
Syntax error
IIFE executed!
Undefined
What’s the difference between parameters and arguments?
None
Parameters are actual values
Arguments are placeholders
Parameters are placeholders; arguments are actual values
What happens if a function doesn’t have a return statement?
Returns 0
Returns undefined
Returns null
Throws error
What is the output?
const double = n => n * 2;
console.log(double(5));
10
5
undefined
Error
What will be the result?
Prints immediately
Prints after 1 second
Error
Never prints
What is the main purpose of using callbacks in JavaScript?
To delay function execution
To handle asynchronous operations
To make loops faster
To define global variables
What does IIFE stand for?
Immediate Invocation Function Execution
Immediately Invoked Function Expression
Instant Internal Function Execution
Internal Invocation Function Expression
Which of the following is an example of an IIFE?
function foo() { }
(function() { console.log("Run!"); })();
const foo = () => {}
let foo = function bar() {}
What is a main advantage of using an IIFE?
Makes function global
Protects variables from global scope
Returns undefined
Works only in ES6
What is an anonymous function?
A function with no return value
A function without a name
A function that cannot be called
A function that runs immediately
Which of the following is an anonymous function used as a callback?
setTimeout(function() { console.log("Hi"); }, 1000);
function greet() {}
const greet = () => {}
function foo(bar) {}
Which of the following is a pure function?
Modifies a global variable
Returns same output for same input
Depends on external state
Uses console.log() inside
What is an impure function?
Returns same value every time
Has no parameters
Modifies external state or depends on it
Anonymous function
What is a closure in JavaScript?
A function that closes after execution
A function that remembers variables from outer scope
An arrow function
A function expression
What will this code print?
0 1
1 2
1 1
Error
Why are closures useful?
For modular and private state
To make global variables
To print values only
To avoid using functions
