Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

JavaScript Functions Quiz

Total questions: 30

Worksheet time: 15mins

Name
Class
Date
1.

What keyword is used to define a function in JavaScript?

a)

define

b)

func

c)

function

d)

method

2.

Which of the following defines a function expression?

a)

function greet() {}

b)

const greet = function() {};

c)

function = greet() {};

d)

let greet = () => {}

3.

Which function type is not hoisted in JavaScript?

a)

Function declaration

b)

Function expression

c)

Arrow function

d)

Both B and C

4.

What will this code print?

console.log(square(4));

const square = n => n * n;

a)

16

b)

Error

c)

undefined

d)

NaN

5.

Arrow functions were introduced in which version of JavaScript?

a)

ES5

b)

ES6

c)

ES7

d)

ES2019

6.

What is the correct syntax for an arrow function that adds two numbers?

a)

(a, b) => a + b

b)

a, b => { return a + b }

c)

a, b -> a + b

d)

=> (a + b)

7.

What is the output of this function?

a)

Hello

b)

Hello undefined

c)

Hello Guest

d)

Error

8.

Which of the following returns a value from a function?

a)

output

b)

echo

c)

return

d)

print

9.

What is a higher-order function?

a)

A function that calls itself

b)

A function that takes or returns another function

c)

A function declared inside another

d)

A recursive function

10.

Which of the following is an example of a callback?

a)

Function passed as argument

b)

Function that runs first

c)

Function without parameters

d)

Function with default values

11.

What will this output be?

a)

greet

b)

callback

c)

Hi!

d)

Error

12.

What is printed here?

a)

5

b)

undefined

c)

Error

d)

5 undefined

13.

In JavaScript, this keyword inside an arrow function refers to:

a)

The global object

b)

The function itself

c)

Its parent scope

d)

Always undefined

14.

Which is a valid anonymous function?

a)

function() { console.log('Hello'); }

b)

function sayHi() {}

c)

sayHi = () => {}

d)

var fn = function named() {}

15.

What does this code output?

(function() {

console.log("IIFE executed!");

})();

a)

Nothing

b)

Syntax error

c)

IIFE executed!

d)

Undefined

16.

What’s the difference between parameters and arguments?

a)

None

b)

Parameters are actual values

c)

Arguments are placeholders

d)

Parameters are placeholders; arguments are actual values

17.

What happens if a function doesn’t have a return statement?

a)

Returns 0

b)

Returns undefined

c)

Returns null

d)

Throws error

18.

What is the output?

const double = n => n * 2;

console.log(double(5));

a)

10

b)

5

c)

undefined

d)

Error

19.

What will be the result?

a)

Prints immediately

b)

Prints after 1 second

c)

Error

d)

Never prints

20.

What is the main purpose of using callbacks in JavaScript?

a)

To delay function execution

b)

To handle asynchronous operations

c)

To make loops faster

d)

To define global variables

21.

What does IIFE stand for?

a)

Immediate Invocation Function Execution

b)

Immediately Invoked Function Expression

c)

Instant Internal Function Execution

d)

Internal Invocation Function Expression

22.

Which of the following is an example of an IIFE?

a)

function foo() { }

b)

(function() { console.log("Run!"); })();

c)

const foo = () => {}

d)

let foo = function bar() {}

23.

What is a main advantage of using an IIFE?

a)

Makes function global

b)

Protects variables from global scope

c)

Returns undefined

d)

Works only in ES6

24.

What is an anonymous function?

a)

A function with no return value

b)

A function without a name

c)

A function that cannot be called

d)

A function that runs immediately

25.

Which of the following is an anonymous function used as a callback?

a)

setTimeout(function() { console.log("Hi"); }, 1000);

b)

function greet() {}

c)

const greet = () => {}

d)

function foo(bar) {}

26.

Which of the following is a pure function?

a)

Modifies a global variable

b)

Returns same output for same input

c)

Depends on external state

d)

Uses console.log() inside

27.

What is an impure function?

a)

Returns same value every time

b)

Has no parameters

c)

Modifies external state or depends on it

d)

Anonymous function

28.

What is a closure in JavaScript?

a)

A function that closes after execution

b)

A function that remembers variables from outer scope

c)

An arrow function

d)

A function expression

29.

What will this code print?

a)

0 1

b)

1 2

c)

1 1

d)

Error

30.

Why are closures useful?

a)

For modular and private state

b)

To make global variables

c)

To print values only

d)

To avoid using functions