What is the result of evaluating:
(true && false) || true
true
Which keyword is used to declare a variable that cannot be reassigned in JavaScript?
const
What is the output of this code?
let arr = [1, 2, 3, 4, 5];
for (let i = 0; i < arr.length; i++) {
if (i === 2) break;
console.log(arr[i]);
}
1 2
What does the 'break' statement do in a loop?
Terminates the loop entirely and continues with the next statement after the loop.
What will be the output of the following code?
let x = 10;
if (x > 5) {
console.log("Greater");
}
else {
console.log("Less or Equal");
}
In range
What is the purpose of the 'default' case in a switch statement?
It acts as a fallback if none of the specified case matches occur.
Which of the following correctly uses a ternary operator to assign a value?
let result = (x > 5) ? "yes" : "no";
What is the correct way to write a JavaScript array?
let colors = ["red", "green", "blue"]
How many times will this for loop execute?
for (let i = 0; i < 5; i++) {
console.log(i);
}
5 times (0, 1, 2, 3, 4)
What will be the output of the following code?
let x = 10;
if (x > 5) {
console.log("Greater");
}
else {
console.log("Less or Equal");
}
Greater
What is the output of this code?
let age = 20;
let status = (age >= 18) ? "Adult" : "Minor"; console.log(status);
Adult
What does this string method return?
let str = "Hello World";
console.log(str.indexOf("o"));
4
What will be logged?
let arr = [3, 1, 4, 1, 5];
arr.sort();
console.log(arr);
[1, 1, 3, 4, 5]
What is the output of this while loop?
let i = 0;
while (i < 3) {
console.log(i);
i++;
}
0 1 2
What will be logged?
let arr = [1, 2, 3, 4, 5];
for (let i = 0; i < arr.length; i++) {
if (i === 2) continue;
console.log(arr[i]);
}
1 2 4 5
What will be the output of this code?
let num = 2;
switch(num) {
case 1:
console.log("One");
case 2:
console.log("Two");
case 3:
console.log("Three");
break;
default:
console.log("Other");
}
Two Three
What is the output?
let num = 42.567;
console.log(num.toFixed(2));
42.5
What is the result of this array method?
let arr = [1, 2, 3, 4, 5];
let result = arr.filter(function(x) { return x > 2; }); console.log(result);
[3, 4, 5]
What will be logged?
let i = 0;
do {
console.log(i);
i++;
}
while (i < 3);
No output
What will be logged?
let x = 5;
if (x > 3 && x < 10) {
console.log("In range");
}
else {
console.log("Out of range");
}
In range
Which switch statement correctly handles the case where day equals 3?
A. switch(day) {
case 3: console.log("Wednesday");
default: console.log("Other");
}
B. switch(day) {
case 3: console.log("Wednesday");
break;
default: console.log("Other");
}
C. switch(day) {
if (day === 3):
console.log("Wednesday");
}
D. switch(day = 3) {
case 3: console.log("Wednesday");
break;
}
B.
What is the result of this string method?
let str = "JavaScript"; console.log(str.substring(0, 4));
Java
What will be logged?
let arr = [1, 2, 3, 4];
let result = arr.reduce(function(sum, x) { return sum + x; }, 0);
console.log(result);
10
What does the forEach method do?
let arr = [1, 2, 3];
arr.forEach(function(num) { console.log(num * 2); });
Logs 2, 4, 6 (each element multiplied by 2)
concat()
slice()
indexOf()
pop()
joins two or more strings
extracts a part of a string and returns the extracted part in a new string.
searches an array for an element value and returns its position.
removes the last element from an array