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?
<script>
<meta>
<link>
<style>
3 Which keyword declares a block-scoped variable that can be reassigned?
define
let
const
static
4 Which keyword declares a block-scoped binding that cannot be reassigned?
var
value
let
const
5
What is the data type of the value "JavaScript"?
6 Which JavaScript value represents an intentionally empty or absent value?
0
undefined
null
false
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.count
text.length
text.size
text.width
10
Which method converts the string name to uppercase?
name.upperCase()
name.toUpperCase()
name.makeUpper()
name.toLowerCase()
11 Which pair contains the two Boolean values in JavaScript?
1 and 0
true and false
on and off
yes and no
12
What does Number("25") return?
25
undefined
true
"25"
13 Which statement runs a block of code only when a specified condition is true?
if statement
return statement
break statement
for 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
method
procedure
function
16 Which keyword sends a value back from a function?
output
yield
break
return
17 Where can a variable declared inside a function normally be accessed?
18 Which method adds an element to the end of an array?
slice()
pop()
shift()
push()
19
Which index accesses the first element of a JavaScript array named items?
items[first]
items[0]
items[1]
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" };
const user = { name: "Ben" };
user.name = "Ben";
user = null;
23
What is printed by console.log(typeof null, Array.isArray([]));?
null true
object false
object true
undefined false
24
What is the output of console.log(0 ?? 5, 0 || 5);?
0 5
5 0
0 0
5 5
25
What value is produced by the expression 2 + 3 * 4 ** 2?
196
50
66
80
26
What does "JavaScript".slice(4, 10) return?
"Scrip"
"cript"
"Script"
"JavaS"
27
What is printed by let text = " web "; text.trim().toUpperCase(); console.log(text.length);?
5
4
0
3
28
What is printed by console.log(Number.isNaN("hello"), isNaN("hello"));?
true false
false true
false false
true true
29
What is the value of [0, 1, "", "JS", null].filter(Boolean).length?
1
4
2
3
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"); }?
ID required
Enter
Too young
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"); }?
number
number string
string
other
32
What is returned by function total(price, tax = price * 0.1) { return price + tax; } total(200);?
200
210
NaN
220
33
What is the result of function twice(fn, value) { return fn(fn(value)); } twice(x => x + 3, 4);?
7
10
11
14
34
What is printed by let count = 10; { let count = 20; console.log(count); } console.log(count);?
20 followed by 10
10 followed by 10
20 followed by 20
10 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());?
[3, 3, 3]
[0, 0, 0]
[1, 2, 3]
[0, 1, 2]
36
After const values = [1, 2, 3, 4]; const removed = values.splice(1, 2, 9);, what are values and removed?
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]
values is [1, 9, 4]; removed is [2, 3]
37
What is the result of [1, 2, 3, 4].filter(n => n % 2 === 0).map(n => n * n)?
[1, 4, 9, 16]
[2, 4]
[4, 16]
[1, 9]
38
What value is returned by [2, 3, 4].reduce((product, n) => product * n, 1)?
14
24
10
20
39
What is printed by const original = { info: { score: 1 } }; const copy = { ...original }; copy.info.score = 5; console.log(original.info.score);?
TypeError occurs
1
5
undefined
40
What is printed by const item = { name: "Pen", price: 10 }; const { name: label, stock = 0 } = item; console.log(label, stock);?
Pen undefined
Pen 0
name 0
label 10
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 C B E
A D E B C
A B C D E
A D B C E
42
What happens when this code executes?
let x = 1;
function test() {
console.log(x);
let x = 2;
}
test();
1.
2.
undefined.
ReferenceError.
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);
3
2
1
undefined
44
What is the value of result?
const value = Object.create(null);
const result = [
typeof value,
value instanceof Object,
Object.getPrototypeOf(value)
];
["object", false, Object.prototype]
["null", false, null]
["object", false, null]
["object", true, null]
45
What are the final values of x and y?
let x = 0;
const y = x++ || ++x;
x is 2 and y is 1.
x is 1 and y is 0.
x is 1 and y is 1.
x is 2 and y is 2.
46
What happens when an ECMAScript parser processes this statement?
const result = null ?? false || true;
result becomes false.
result becomes true.
result becomes null.
SyntaxError occurs.
47
What is the value of result?
const text = "A😀B";
const result = [
text.length,
text.slice(1, 3),
Array.from(text).length
];
[3, "😀", 4]
[3, "😀", 3]
[4, "😀B", 3]
[4, "😀", 3]
48
What does the following expression return?
"aba".replace(/a/g, (match, offset) => String(offset))
"ab2"
"0b2"
"0ba"
"1b3"
49
What is the result of this comparison?
Number.MAX_SAFE_INTEGER + 1 === Number.MAX_SAFE_INTEGER + 2
true
undefined
RangeError
false
50
What is the value of result?
const result = [
Object.is(NaN, NaN),
Object.is(0, -0),
Boolean(new Boolean(false))
];
[false, false, true]
[false, true, false]
[true, false, true]
[true, 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";
}
"ABCD"
"BC"
"BCD"
"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"];
}
[1, "T"]
[2, "F"]
[2, "T"]
[0, "F"]
53
What happens when f() is called?
let x = 10;
function f(a = x, x = 20) {
return [a, x];
}
f();
[undefined, 20].
ReferenceError.
[10, 20].
[20, 20].
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();
undefined
TypeError
5
9
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(",");
"3:3,3:3,3:3"
"0:3,1:3,2:3"
"3:0,3:1,3:2"
"0:0,1:1,2:2"
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, false, false, true]
[3, true, true, true]
[2, true, false, true]
[3, 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, 4], values = [1, 9, 8, 7]
removed = [9, 8], values = [1, 7, 3, 4]
removed = [2, 3], values = [1, 9, 8, 7]
removed = [2, 3], values = [1, 9, 8, 7, 4]
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"], "second", 1]
[["1", symbol], "second", 1]
[["1", "1"], "first", 1]
[["1"], "first", 0]
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];
[2, "undefined", true]
[2, "function", false]
[2, "function", true]
[undefined, "undefined", 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, false, undefined]
[true, true, 2]
[false, true, 1]
[true, false, 1]
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 →