Here are Top 25 multiple-choice questions (MCQs) focused on the HTML5 features and elements in JavaScript MCQs, along with their answers and explanations.

PRACTICE IT NOW TO SHARPEN YOUR CONCEPT AND KNOWLEDGE

view hide answers

1. What is the purpose of an `else if` statement in JavaScript?

  • To declare a variable
  • To create a function
  • To control the flow of code based on multiple conditions
  • To define an object

2. What will be the result of the following code?
var x = 2; 

if (x > 3) 

 { 

       console.log("Hello, world!"); 

 } else if (x < 1)  

{ 

       console.log("Goodbye, world!"); 

 } else { 

       console.log("Hi there, world!"); 

 } 

  • "Hello, world!" will be logged
  • "Goodbye, world!" will be logged
  • "Hi there, world!" will be logged
  • None of the above

3. Which loop in JavaScript is used to iterate over the properties of an object?

  • for loop
  • while loop
  • for...of loop
  • for...in loop

4. What does the `break` statement do in JavaScript?

  • It continues to the next iteration of a loop
  • It exits the current loop or switch statement
  • It defines a function
  • It creates a new object

5. What is the purpose of a `for` loop in JavaScript?

  • To declare a variable
  • To create a function
  • To control the flow of code based on a condition
  • To repeatedly execute a block of code a specific number of times

6. Which keyword is used to declare a loop in JavaScript?

  • loop
  • repeat
  • for
  • iterate

7. What will be the result of the following `for` loop?
for (var i = 0; i < 5; i++) 
{ 
console.log(i); 
} 

  • 0, 1, 2, 3, 4 will be logged
  • 1, 2, 3, 4, 5 will be logged
  • 5, 4, 3, 2, 1 will be logged
  • An error will occur

8. What is the purpose of a `while` loop in JavaScript?

  • To declare a variable
  • To create a function
  • To control the flow of code based on a condition
  • To repeatedly execute a block of code as long as a condition is true

9. Which keyword is used to start a `while` loop in JavaScript?

  • loop
  • start
  • while
  • repeat

10. What does the `continue` statement do in JavaScript?

  • It exits the current loop or switch statement
  • It continues to the next iteration of a loop
  • It defines a function
  • It creates a new object

11. What is the purpose of a `do...while` loop in JavaScript?

  • To declare a variable
  • To create a function
  • To control the flow of code based on a condition
  • To repeatedly execute a block of code at least once and then as long as a condition is true

12. Which keyword is used to start a `do...while` loop in JavaScript?

  • loop
  • start
  • do
  • while

13. What will be the result of the following `do...while` loop?
var i = 0;
do {
console.log(i);i++;
} while (i < 5);

  • 0, 1, 2, 3, 4 will be logged
  • 1, 2, 3, 4, 5 will be logged
  • 5, 4, 3, 2, 1 will be logged
  • An error will occur

14. What is the purpose of a `switch` statement in JavaScript?

  • To declare a variable
  • To create a function
  • To control the flow of code based on multiple conditions
  • To define an object

15. Which keyword is used to start a `switch` statement in JavaScript?

  • switch
  • case
  • select
  • condition

16. What is the purpose of a `case` statement in a `switch` statement in JavaScript?

  • To declare a variable
  • To create a function
  • To define an object
  • To specify code to run when a specific condition is met

17. What will be the result of the following `switch` statement?

var day = "Monday";

switch (day) {

case "Monday".console.log("It's the start of the week.");

break;

case "Friday".console.log("It's the end of the week.");

break;

default. console.log("It's a regular day.");

}

  • "It's the start of the week." will be logged
  • "It's the end of the week." will be logged
  • "It's a regular day." will be logged
  • All of the above will be logged

18. What is the purpose of the `default` case in a `switch` statement?

  • To declare a variable
  • To create a function
  • To define an object
  • To specify code to run when no other cases match

19. What will be the result of the following `switch` statement?
 var day = "Wednesday";
 
 switch (day) {
 
 case "Monday".console.log("It's the start of the week.");
 
 break;
 
 case "Friday".console.log("It's the end of the week.");
 
 break;
 
 default.console.log("It's a regular day.");
 
 }
 

  • "It's the start of the week." will be logged
  • "It's the end of the week." will be logged
  • "It's a regular day." will be logged
  • None of the above

20. What is the purpose of the `break` statement in a `switch` statement in JavaScript?

  • To continue to the next case
  • To exit the current loop
  • To specify the default case
  • To exit the `switch` statement

21. What is the purpose of an `if` statement in JavaScript?

  • To declare a variable
  • To create a function
  • To control the flow of code based on a condition
  • To define an object

22. Which keyword is used to start an `if` statement in JavaScript?

  • then
  • do
  • if
  • start

23. What will be the result of the following code?\
 var x = 5;
  
 if (x > 3)
  
 { 
  
 console.log("Hello, world!");
  
 }
  

  • "Hello, world!" will be logged
  • "Hello, world!" will not be logged
  • An error will occur
  • x will be set to 3

24. What is the purpose of an `else` statement in JavaScript?

  • To declare a variable
  • To create a function
  • To define an object
  • To specify code to run when the `if` condition is false

25. What will be the result of the following code?
  
var x = 2;

if (x > 3)
 {
 
 console.log("Hello, world!");
 
 } else {
 
 console.log("Goodbye, world!");
 
 }
 

  • "Hello, world!" will be logged
  • "Goodbye, world!" will be logged
  • Both "Hello, world!" and "Goodbye, world!" will be logged
  • An error will occur

Share with : Share on Linkedin Share on Twitter Share on WhatsApp Share on Facebook