0% found this document useful (0 votes)
22 views7 pages

IP Chapter Four

The document contains multiple-choice questions (MCQs) related to JavaScript concepts, covering data types, variable handling, control structures, loops, functions, and event handling. Each question is followed by the correct answer and a brief explanation. The content is designed to test knowledge of JavaScript fundamentals and best practices.

Uploaded by

kerorsaelias
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)
22 views7 pages

IP Chapter Four

The document contains multiple-choice questions (MCQs) related to JavaScript concepts, covering data types, variable handling, control structures, loops, functions, and event handling. Each question is followed by the correct answer and a brief explanation. The content is designed to test knowledge of JavaScript fundamentals and best practices.

Uploaded by

kerorsaelias
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

IP Chapter Four (MCQs)

1. Which of the following is NOT a JavaScript data type?

A. Number
B. Boolean
C. String
D. Character

Answer: D
Explanation: JavaScript does not have a separate Character data type. Characters are represented
as strings of length 1.

2. JavaScript variables are said to be ______ typed.

A. Strongly
B. Statically
C. Dynamically
D. Strictly

Answer: C
Explanation: JavaScript variables can change their data type during program execution.

3. Which symbol is used for assignment in JavaScript?

A. ==
B. ===
C. =
D. :=

Answer: C
Explanation: The single equals sign (=) assigns a value to a variable.

1
4. What will be the data type of the variable weekend?
weekend = (day == "Sunday") || (day == "Saturday");

A. String
B. Number
C. Boolean
D. Undefined

Answer: C
Explanation: Logical operators (||) always return a Boolean value (true or false).

5. Which statement is used to execute code only when a condition is true?

A. for
B. while
C. if
D. switch

Answer: C
Explanation: The if statement executes code when the specified condition evaluates to true.

6. Curly braces { } in JavaScript are used to create:

A. Variables
B. Expressions
C. Compound statements
D. Conditions

Answer: C
Explanation: Curly braces group multiple statements into a single compound (block) statement.

7. Which keyword is used to provide an alternate block when an if condition


fails?

2
A. switch
B. default
C. else
D. break

Answer: C
Explanation: The else block executes when the if condition is false.

8. Which structure is best when decisions depend on a single variable?

A. if
B. if…else
C. while
D. switch

Answer: D
Explanation: switch is more readable and efficient when comparing one variable against many
values.

9. What happens if break is omitted in a switch case?

A. Program stops
B. Syntax error occurs
C. Next case executes
D. Default case runs only

Answer: C
Explanation: Without break, execution continues into the next case (fall-through).

10. Which loop runs as long as a condition remains true?

A. for
B. while

3
C. do–while
D. switch

Answer: B
Explanation: A while loop continues execution as long as its condition evaluates to true.

11. How many times will this loop execute?


for (x = 6000; x < 0; x--) {
[Link](x);
}

A. 6000
B. Infinite
C. 1
D. 0

Answer: D
Explanation: The condition x < 0 is false initially, so the loop never executes.

12. When should a for loop be preferred over a while loop?

A. When condition is complex


B. When iterations are infinite
C. When number of iterations is known
D. When using logical operators

Answer: C
Explanation: for loops are ideal when the number of iterations is predetermined.

13. Which part of a for loop updates the loop variable?

A. Initialization
B. Condition

4
C. Operation
D. Block

Answer: C
Explanation: The operation (increment/decrement) updates the loop variable after each
iteration.

14. What is the output of:


x = 1;
while (x < 3) {
[Link](x);
x++;
}

A. 123
B. 12
C. 23
D. 13

Answer: B
Explanation: The loop runs for x = 1 and x = 2.

15. A JavaScript function is mainly used to:

A. Increase memory usage


B. Repeat code
C. Reduce code duplication
D. Declare variables only

Answer: C
Explanation: Functions promote code reuse and improve maintainability.

16. Which keyword is used to define a function?

5
A. def
B. function
C. method
D. define

Answer: B
Explanation: JavaScript uses the function keyword to define functions.

17. Arrow functions were introduced in:

A. ES3
B. ES5
C. ES6
D. ES7

Answer: C
Explanation: Arrow functions were introduced in ECMAScript 6 (ES6).

18. Objects in JavaScript store data as:

A. Arrays
B. Indexed values
C. Key–value pairs
D. Functions only

Answer: C
Explanation: JavaScript objects consist of properties stored as key–value pairs.

19. Which method is considered best practice for event handling?

A. onclick
B. onhover
C. addEventListener
D. attachEvent

6
Answer: C
Explanation: addEventListener allows multiple handlers and better separation of concerns.

20. Why is client-side validation important?

A. It replaces server validation


B. It increases server load
C. It provides instant user feedback
D. It stores data permanently

Answer: C
Explanation: Client-side validation improves user experience by catching errors early.

You might also like