wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Mastering JavaScript Concepts

Total questions: 20

Worksheet time: 7mins

Name
Class
Date
1.

What is the scope of a variable declared with 'var' inside a function?

a)

Function-scoped

b)

Global-scoped

c)

Block-scoped

d)

Class-scoped

2.

What will the following code output?
console.log(x);
var x = 5;

a)

undefined

b)

null

c)

ReferenceError

d)

5

3.

Which of the following statements about 'let' is true?

a)

'let' declares variables with function scope.

b)

'let' is used to declare constants.

c)

'let' can only be used in global scope.

d)

'let' declares variables with block scope.

4.

What is the result of the following code?
let a = 1;
if (true) { let a = 2; }
console.log(a);

a)

2

b)

undefined

c)

1

d)

ReferenceError

5.

What is the output of the following code?
function test()
{
console.log(a);
var a = 3;
}
test();

a)

null

b)

undefined

c)

3

d)

ReferenceError

6.

What is the Temporal Dead Zone (TDZ)?

a)

The TDZ refers to the time when a variable is globally accessible.

b)

The TDZ is the time when a variable can be accessed from any scope.

c)

The TDZ is the period after a variable is declared but before it is initialized.

d)

The Temporal Dead Zone (TDZ) is the time between entering a block scope and the variable declaration where the variable cannot be accessed.

7.

Which of the following is true about closures?

a)

Closures are only applicable in object-oriented programming.

b)

Closures cannot retain references to their outer scope.

c)

Closures can only access global variables.

d)

Closures can access variables from their containing scope even after that scope has finished executing.

8.

What will the following code output? function outer()
{ let x = 10;
function inner()
{ console.log(x);}
return inner;
}
const innerFunc = outer();
innerFunc();

a)

10

b)

20

c)

undefined

d)

10.5

9.

What is the difference between function declarations and function expressions?

a)

Function declarations cannot take parameters.

b)

Function declarations are hoisted; function expressions are not.

c)

Function expressions are always named.

d)

Function declarations can only be used once.

10.

What will the following code output?
const foo = () => { return 5};
console.log(foo());

a)

0

b)

5.5

c)

10

d)

5

11.

What is the output of the following code?
let x;
console.log(x ?? 'default');

a)

undefined

b)

'default'

c)

null

d)

default

12.

What will the following code output?
let a = null;
let b = 5;
console.log(a || b);

a)

undefined

b)

5

c)

10

d)

null

13.

What is the result of the following code?
let x = 1;
if (true) { let x = 2; }
console.log(x);

a)

undefined

b)

ReferenceError

c)

1

d)

2

14.

What is the output of the following code?
const a = 1;
a = 2;
console.log(a);

a)

2

b)

undefined

c)

1

d)

TypeError

15.

What will the following code output?
function test()
{ console.log(typeof x); }
test();
var x = 10;

a)

number

b)

undefined

c)

string

d)

null

16.

What is the output of the following code?
let a = 1;
if (true) {
let a = 2;
console.log(a);
}
console.log(a);

a)

3

b)

undefined

c)

2 and 1

d)

2 1

17.

What is the result of the following code? const obj = { name: 'John' }; obj = { name: 'Doe' };

a)

TypeError: Assignment to constant variable.

b)

TypeError: Cannot read property 'name' of undefined

c)

ReferenceError: obj is not defined

d)

SyntaxError: Unexpected token

18.

What will the following code output?
let a = 1;
let b = 2;
console.log(a && b);

a)

2

b)

undefined

c)

1

d)

true

19.

What is the output of the following code? let a = 0; console.log(a ?? 5);

a)

0

b)

5

c)

null

d)

undefined

20.

What is the output of the following code?
let a = 1;
let b = null;
console.log(a ?? b);

a)

null

b)

undefined

c)

1

d)

0