NEW
Font size
WorksheetsMastering JavaScript Concepts
Total questions: 20
Worksheet time: 7mins
What is the scope of a variable declared with 'var' inside a function?
Function-scoped
Global-scoped
Block-scoped
Class-scoped
What will the following code output?
console.log(x);
var x = 5;
undefined
null
ReferenceError
5
Which of the following statements about 'let' is true?
'let' declares variables with function scope.
'let' is used to declare constants.
'let' can only be used in global scope.
'let' declares variables with block scope.
What is the result of the following code?
let a = 1;
if (true) { let a = 2; }
console.log(a);
2
undefined
1
ReferenceError
What is the output of the following code?
function test()
{
console.log(a);
var a = 3;
}
test();
null
undefined
3
ReferenceError
What is the Temporal Dead Zone (TDZ)?
The TDZ refers to the time when a variable is globally accessible.
The TDZ is the time when a variable can be accessed from any scope.
The TDZ is the period after a variable is declared but before it is initialized.
The Temporal Dead Zone (TDZ) is the time between entering a block scope and the variable declaration where the variable cannot be accessed.
Which of the following is true about closures?
Closures are only applicable in object-oriented programming.
Closures cannot retain references to their outer scope.
Closures can only access global variables.
Closures can access variables from their containing scope even after that scope has finished executing.
What will the following code output? function outer()
{ let x = 10;
function inner()
{ console.log(x);}
return inner;
}
const innerFunc = outer();
innerFunc();
10
20
undefined
10.5
What is the difference between function declarations and function expressions?
Function declarations cannot take parameters.
Function declarations are hoisted; function expressions are not.
Function expressions are always named.
Function declarations can only be used once.
What will the following code output?
const foo = () => { return 5};
console.log(foo());
0
5.5
10
5
What is the output of the following code?
let x;
console.log(x ?? 'default');
undefined
'default'
null
default
What will the following code output?
let a = null;
let b = 5;
console.log(a || b);
undefined
5
10
null
What is the result of the following code?
let x = 1;
if (true) { let x = 2; }
console.log(x);
undefined
ReferenceError
1
2
What is the output of the following code?
const a = 1;
a = 2;
console.log(a);
2
undefined
1
TypeError
What will the following code output?
function test()
{ console.log(typeof x); }
test();
var x = 10;
number
undefined
string
null
What is the output of the following code?
let a = 1;
if (true) {
let a = 2;
console.log(a);
}
console.log(a);
3
undefined
2 and 1
2 1
What is the result of the following code? const obj = { name: 'John' }; obj = { name: 'Doe' };
TypeError: Assignment to constant variable.
TypeError: Cannot read property 'name' of undefined
ReferenceError: obj is not defined
SyntaxError: Unexpected token
What will the following code output?
let a = 1;
let b = 2;
console.log(a && b);
2
undefined
1
true
What is the output of the following code? let a = 0; console.log(a ?? 5);
0
5
null
undefined
What is the output of the following code?
let a = 1;
let b = null;
console.log(a ?? b);
null
undefined
1
0
