JavaScript Function Closures Quiz

JavaScript Function Closures Quiz

Assessment

Quiz

Computers

5th Grade

Medium

Created by

Tanvir Hossain

Used 1+ times

FREE Resource

Student preview

quiz-placeholder

8 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is a closure in JavaScript?

A method to create global variables.

A way to define a function inside another function.

A type of variable that can only be used inside a function.

A function that can access its parent scope even after the parent function has closed.

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What happens to local variables when a function is finished?

They are deleted.

They become global variables.

They are stored in memory forever.

They can be accessed by other functions.

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the purpose of a self-invoking function?

To create a function that runs only once.

To increase the performance of the code.

To create multiple functions at once.

To define global variables.

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What will happen if you create a variable without a declaration keyword?

It will be undefined.

It will cause an error.

It will be a local variable.

It will always be a global variable.

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

How can you protect a variable from being changed by other code?

By defining it inside a loop.

By using a closure.

By using the var keyword.

By declaring it as a global variable.

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the lifetime of a global variable?

Only while the function is running.

Until the page is discarded.

Until the variable is deleted.

Until the browser is closed.

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What does the 'this' keyword refer to in a function?

The current object the function is being executed in.

The global scope.

The parent function.

The first argument of the function.

8.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the main issue with using a global counter variable?

It will cause an error if modified.

It cannot be accessed by functions.

Any code can change it without permission.

It will always be undefined.