Explore topic-wise MCQs in Javascript.

This section includes 10 Mcqs, each offering curated multiple-choice questions to sharpen your Javascript knowledge and support exam preparation. Choose a topic below to get started.

1.

Which is a more efficient code snippet?Code 1 :for(var n=10;n>=1;n--){ document.writeln(n);}Code 2 :var n=10;while(n>=1){ document.writeln(n); n++;}

A. Code 2
B. Code 1
C. Cannot Compare
D. Both Code 1 and Code 2
E. None of these
Answer» C. Cannot Compare
2.

What would be the most appropriate output for the following code snippet?var p=15 , q=10var object = { p : 20 }with(object) { alert(q)}

A. 20
B. Error
C. 15
D. 10
E. None of these
Answer» E. None of these
3.

What happens in the following javascript code snippet?var num = 1;while (num < 15) { console.log(num); num++;}

A. An exception is thrown
B. An error is displayed
C. The values of count are logged or stored in a particular location or storage
D. The value of count from 1 to 14 is displayed in the console
E. None of these
Answer» E. None of these
4.

Consider the following statementsswitch(expression){ statements}In the above switch syntax, the expression is compared with the case labels using which of the following operator(s)?

A. ===
B. equal
C. equals
D. ==
E. None of these
Answer» B. equal
5.

Which is a more efficient code snippet?

A. Code 2
B. Code 1
C. Cannot Compare
D. Both Code 1 and Code 2
E. None of these
Answer» C. Cannot Compare
6.

A conditional expression is also called a _______________.

A. If-then-else statement
B. Alternative to if-else
C. Immediate if
D. All of above
E. None of these
Answer» D. All of above
7.

When an empty statement is encountered, a JavaScript interpreter __________.

A. Throws an error
B. Shows a warning
C. Ignores the statement
D. Prompts to complete the statement
E. None of these
Answer» D. Prompts to complete the statement
8.

What would be the most appropriate output for the following code snippet?

A. 20
B. Error
C. 15
D. 10
E. None of these
Answer» E. None of these
9.

What happens in the following javascript code snippet?

A. An exception is thrown
B. An error is displayed
C. The values of count are logged or stored in a particular location or storage
D. The value of count from 1 to 14 is displayed in the console
E. None of these
Answer» E. None of these
10.

The var and function are __________.

A. Prototypes
B. Data types
C. Keywords
D. Declaration statements
E. None of these
Answer» E. None of these