Unit 4: JavaScript Fundamentals - Practice Quiz
1 What is JavaScript primarily used for in web development?
2 Which HTML element is used to include JavaScript code in a web page?
<meta>
<link>
<script>
<style>
3 Which keyword declares a block-scoped variable that can be reassigned?
let
static
const
define
4 Which keyword declares a block-scoped binding that cannot be reassigned?
const
let
value
var
5
What is the data type of the value "JavaScript"?
6 Which JavaScript value represents an intentionally empty or absent value?
null
undefined
false
0
7 Which operator checks both value and data type for equality?
!=
===
==
=
8
What is the result of the expression 10 % 3?
1
3
3.33
0
9
Which property returns the number of characters in a string named text?
text.size
text.count
text.length
text.width
10
Which method converts the string name to uppercase?
name.makeUpper()
name.toLowerCase()
name.toUpperCase()
name.upperCase()
11 Which pair contains the two Boolean values in JavaScript?
on and off
true and false
yes and no
1 and 0
12
What does Number("25") return?
"25"
true
25
undefined
13 Which statement runs a block of code only when a specified condition is true?
break statement
for statement
if statement
return statement
14
Which keyword provides an alternative block when an if condition is false?
else
case
then
default
15 Which keyword is commonly used to declare a JavaScript function?
define
procedure
function
method
16 Which keyword sends a value back from a function?
output
return
yield
break
17 Where can a variable declared inside a function normally be accessed?
18 Which method adds an element to the end of an array?
pop()
push()
slice()
shift()
19
Which index accesses the first element of a JavaScript array named items?
items[0]
items[1]
items[first]
items[-1]
20
How can the name property of an object called student be accessed using dot notation?
student(name)
student->name
student.name
student::name
21
What happens when a browser encounters <script defer src="app.js"></script> in the document <head>?
22
Given const user = { name: "Ana" };, which statement executes without causing an error?
user.name = "Ben";
user = null;
user = { name: "Ben" };
const user = { name: "Ben" };
23
What is printed by console.log(typeof null, Array.isArray([]));?
object true
object false
undefined false
null true
24
What is the output of console.log(0 ?? 5, 0 || 5);?
5 5
0 0
0 5
5 0
25
What value is produced by the expression 2 + 3 * 4 ** 2?
66
50
80
196
26
What does "JavaScript".slice(4, 10) return?
"JavaS"
"cript"
"Script"
"Scrip"
27
What is printed by let text = " web "; text.trim().toUpperCase(); console.log(text.length);?
3
5
4
0
28
What is printed by console.log(Number.isNaN("hello"), isNaN("hello"));?
true false
false false
true true
false true
29
What is the value of [0, 1, "", "JS", null].filter(Boolean).length?
4
3
2
1
30
What is printed by const age = 20; const hasID = false; if (age >= 18 && hasID) { console.log("Enter"); } else if (age >= 18) { console.log("ID required"); } else { console.log("Too young"); }?
Too young
ID required
Enter
31
What is printed by const value = "2"; switch (value) { case 2: console.log("number"); break; case "2": console.log("string"); break; default: console.log("other"); }?
string
other
number string
number
32
What is returned by function total(price, tax = price * 0.1) { return price + tax; } total(200);?
220
200
210
NaN
33
What is the result of function twice(fn, value) { return fn(fn(value)); } twice(x => x + 3, 4);?
14
11
7
10
34
What is printed by let count = 10; { let count = 20; console.log(count); } console.log(count);?
10 followed by 10
10 followed by 20
20 followed by 10
20 followed by 20
35
What is returned by function makeFunctions() { const result = []; for (let i = 0; i < 3; i++) result.push(() => i); return result; } makeFunctions().map(fn => fn());?
[0, 1, 2]
[1, 2, 3]
[0, 0, 0]
[3, 3, 3]
36
After const values = [1, 2, 3, 4]; const removed = values.splice(1, 2, 9);, what are values and removed?
values is [1, 9, 4]; removed is [2, 3]
values is [1, 2, 9, 4]; removed is [3]
values is [1, 9, 3, 4]; removed is [2]
values is [1, 4]; removed is [2, 3, 9]
37
What is the result of [1, 2, 3, 4].filter(n => n % 2 === 0).map(n => n * n)?
[2, 4]
[4, 16]
[1, 9]
[1, 4, 9, 16]
38
What value is returned by [2, 3, 4].reduce((product, n) => product * n, 1)?
10
14
20
24
39
What is printed by const original = { info: { score: 1 } }; const copy = { ...original }; copy.info.score = 5; console.log(original.info.score);?
1
5
undefined
TypeError occurs
40
What is printed by const item = { name: "Pen", price: 10 }; const { name: label, stock = 0 } = item; console.log(label, stock);?
Pen undefined
label 10
name 0
Pen 0
41
What is printed by the following JavaScript code?
console.log("A");
Promise.resolve().then(() => console.log("B"));
queueMicrotask(() => console.log("C"));
setTimeout(() => console.log("E"), 0);
console.log("D");
A D B C E
A D E B C
A B C D E
A D C B E
42
What happens when this code executes?
let x = 1;
function test() {
console.log(x);
let x = 2;
}
test();
1.
ReferenceError.
2.
undefined.
43
In an ordinary non-strict script, what is printed?
const config = Object.freeze({
nested: { value: 1 }
});
config.nested.value = 2;
config.nested = { value: 3 };
console.log(config.nested.value);
undefined
1
2
3
44
What is the value of result?
const value = Object.create(null);
const result = [
typeof value,
value instanceof Object,
Object.getPrototypeOf(value)
];
["object", true, null]
["object", false, null]
["object", false, Object.prototype]
["null", false, null]
45
What are the final values of x and y?
let x = 0;
const y = x++ || ++x;
x is 2 and y is 2.
x is 1 and y is 0.
x is 2 and y is 1.
x is 1 and y is 1.
46
What happens when an ECMAScript parser processes this statement?
const result = null ?? false || true;
result becomes true.
SyntaxError occurs.
result becomes null.
result becomes false.
47
What is the value of result?
const text = "A😀B";
const result = [
text.length,
text.slice(1, 3),
Array.from(text).length
];
[4, "😀B", 3]
[4, "😀", 3]
[3, "😀", 4]
[3, "😀", 3]
48
What does the following expression return?
"aba".replace(/a/g, (match, offset) => String(offset))
"0b2"
"0ba"
"ab2"
"1b3"
49
What is the result of this comparison?
Number.MAX_SAFE_INTEGER + 1 === Number.MAX_SAFE_INTEGER + 2
RangeError
false
undefined
true
50
What is the value of result?
const result = [
Object.is(NaN, NaN),
Object.is(0, -0),
Boolean(new Boolean(false))
];
[true, true, false]
[true, false, true]
[false, false, true]
[false, true, false]
51
What is the final value of result?
let result = "";
switch (2) {
case 1:
result += "A";
case 2:
result += "B";
default:
result += "C";
case 3:
result += "D";
}
"BC"
"BCD"
"ABCD"
"BD"
52
What is the value of result after this code runs?
let a = 0;
let b = 1;
let result;
if (a = b && 0 || 2) {
result = [a, "T"];
} else {
result = [a, "F"];
}
[0, "F"]
[2, "F"]
[2, "T"]
[1, "T"]
53
What happens when f() is called?
let x = 10;
function f(a = x, x = 20) {
return [a, x];
}
f();
[10, 20].
[undefined, 20].
[20, 20].
ReferenceError.
54
What does the final expression return?
const obj = {
x: 5,
make() {
return () => this.x;
}
};
const fn = obj.make();
const other = { x: 9, fn };
other.fn();
9
undefined
5
TypeError
55
What string is produced?
const callbacks = [];
for (var i = 0; i < 3; i++) {
let j = i;
callbacks.push(() => `${i}:${j}`);
}
callbacks.map(fn => fn()).join(",");
"0:0,1:1,2:2"
"3:0,3:1,3:2"
"3:3,3:3,3:3"
"0:3,1:3,2:3"
56
What is the value of result?
const source = [1, , 3];
const mapped = source.map(x => x * 2);
const result = [
mapped.length,
0 in mapped,
1 in mapped,
2 in mapped
];
[3, true, true, true]
[3, false, false, true]
[3, true, false, true]
[2, true, false, true]
57
After this code runs, what are removed and values?
const values = [1, 2, 3, 4];
const removed = values.splice(1, 2, 9, 8, 7);
removed = [2, 3], values = [1, 9, 8, 7, 4]
removed = [2, 3, 4], values = [1, 9, 8, 7]
removed = [9, 8], values = [1, 7, 3, 4]
removed = [2, 3], values = [1, 9, 8, 7]
58
What is the value of result?
const symbol = Symbol("1");
const object = {
[1]: "first",
"1": "second",
[symbol]: "third"
};
const result = [
Object.keys(object),
object[1],
Object.getOwnPropertySymbols(object).length
];
[["1", symbol], "second", 1]
[["1"], "first", 0]
[["1", "1"], "first", 1]
[["1"], "second", 1]
59
What is the value of result?
const source = {
get x() {
return 2;
}
};
const target = { ...source };
const descriptor = Object.getOwnPropertyDescriptor(target, "x");
const result = [target.x, typeof descriptor.get, descriptor.writable];
[undefined, "undefined", true]
[2, "function", false]
[2, "undefined", true]
[2, "function", true]
60
What is the value of result?
const prototype = { x: 1 };
const object = Object.create(prototype);
object.x = 2;
delete object.x;
const result = [
"x" in object,
Object.hasOwn(object, "x"),
object.x
];
[false, true, 1]
[true, true, 2]
[true, false, 1]
[false, false, undefined]
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill. The rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it. What it pays for →