0% found this document useful (0 votes)
2 views4 pages

JavaScript Quiz: Common Errors Explained

The document contains a series of JavaScript code snippets along with multiple-choice questions regarding their outputs. Each question tests knowledge of variable scope, type coercion, function behavior, and control flow in JavaScript. The answers are provided for each question, highlighting common pitfalls and expected outputs.

Uploaded by

lawuneain444
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

JavaScript Quiz: Common Errors Explained

The document contains a series of JavaScript code snippets along with multiple-choice questions regarding their outputs. Each question tests knowledge of variable scope, type coercion, function behavior, and control flow in JavaScript. The answers are provided for each question, highlighting common pitfalls and expected outputs.

Uploaded by

lawuneain444
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1.

let name = "Swan";


[Link](Name);

A. It will print Swan​


B. It will print Name​
C. It will throw a ReferenceError​
D. It will print null
Answer: C

2.
let x = "5";
let y = 2;
[Link](x + y);

A. 7​
B. 52​
C. NaN​
D. Error
Answer: B

3.
let i = 0;
while (i < 5) {
[Link](i);
}

A. i should be declared as var​


B. Condition should use <=​
C. i is never incremented​
D. [Link] is incorrect
Answer: C
4.
let grade = 85; if (grade >= 80) {[Link]("A");} if (grade >= 70) {[Link]("B");}

A. A
B. B
C. A and B
D. Nothing
Answer: C

5.
function add(a, b) {a + b;} [Link](add(3, 4));

A. 7​
B. undefined​
C. NaN​
D. null
Answer: B (no return)

6.
let numbers = [1, 2, 3, 4]; for (let i = 0; i <= [Link]; i++) {[Link](numbers[i]);}

A. It will print all numbers correctly​


B. It will throw a syntax error​
C. It will print undefined at the end​
D. It won’t print anything
Answer: C (loop goes out of bounds at i = 4)

7.
let scores = [10, 20, 30]; let total = 0; for (let i = 0; i < [Link]; i++) {total += scores[i];}
[Link](total);

A. 60​
B. 0​
C. 30​
D. undefined
Answer: A

8.
let score = 100; if (score = 50) {[Link]("Halfway!");} else {[Link]("Not halfway.");}
A. It prints "Halfway!"​
B. It prints "Not halfway."​
C. It throws an error​
D. Nothing happens
Answer: A

9.
let isLoggedIn = false; if (isLoggedIn) {[Link]("Welcome back!");} else if (isLoggedIn ==
false) {[Link]("Please log in");} else {[Link]("Error");}

A. Welcome back!​
B. Please log in​
C. Error​
D. Nothing

✅ Answer: B

10.
let x = 5; let y = 20; if (x > 10 && y > 10) {[Link]("Both big!");} else { [Link]("At least
one is small");}

A. Both big!​
B. At least one is small​
C. Error​
D. Nothing
Answer: B (because x > 10 is false)

11.
function sayName(name) {[Link]("Hello " + name);} sayName();

A. Hello​
B. Hello undefined​
C. Error​
D. Nothing
Answer: B
12.
function test() {let message = "Hello";} [Link](message);

A. It prints “Inside function”​


B. It prints “undefined”​
C. It throws a ReferenceError​
D. It prints nothing
Answer: C

You might also like