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 a JavaScript function?

  • A way to declare a variable
  • A data type for storing text
  • A reusable block of code that performs a specific task
  • A way to define a loop

2. Which keyword is used to declare a function in JavaScript?

  • func
  • method
  • define
  • function

3. What is a parameter in a JavaScript function?

  • A type of object
  • A variable that holds a reference to a function
  • A named variable passed to a function as an input
  • A variable used for counting iterations in a loop

4. What is a JavaScript function's return statement used for?

  • To declare a variable
  • To define a loop
  • To specify code to run when a specific condition is met
  • To specify the value that the function should return

5. What is the result of the following JavaScript function? function add(a, b) { return a + b;}var result = add(3, 5);

  • result will be assigned the value 8.
  • An error will occur.
  • result will be assigned the function add.
  • The function add will log the result.

6. What is a JavaScript object?

  • A way to declare a variable
  • A function that performs a specific task
  • A collection of key-value pairs
  • A way to define a loop

7. How do you access a property of a JavaScript object?

  • By using the dot notation (e.g., object.property)
  • By using square brackets (e.g., object['property'])
  • By using parentheses (e.g., object('property'))
  • By using backticks (e.g., objectproperty`)

8. What is a JavaScript constructor function used for?

  • To perform mathematical operations
  • To create multiple objects with similar properties and methods
  • To specify code to run when a specific condition is met
  • To define a loop

9. Which keyword is used to create a new instance of an object in JavaScript?

  • create
  • instance
  • new
  • object

10. What is the result of the following JavaScript code? function Person(name) { this.name = name;}var person1 = new Person("Alice");var person2 = new Person("Bob");console.log(person1.name);

  • "Alice"
  • "Bob"
  • An error will occur.
  • Both "Alice" and "Bob" will be logged.

11. What is a JavaScript method?

  • A way to declare a variable
  • A data type for storing text
  • A function that is a property of an object
  • A way to define a loop

12. How do you call a method of a JavaScript object?

  • By using the method keyword
  • By using square brackets
  • By using parentheses after the method name
  • By using backticks

13. What is a JavaScript prototype?

  • A way to declare a variable
  • A built-in function in JavaScript
  • An object from which other objects inherit properties
  • A way to define a loop

14. How do you add a method to a JavaScript object's prototype?

  • By using the addMethod keyword
  • By defining the method directly within the object
  • By using the prototype property of the constructor function
  • By using the Object.create() method

15. What is a closure in JavaScript?

  • A way to declare a variable
  • A way to define a loop
  • A function that is nested within another function and has access to the outer function's variables
  • A data type for storing text

16. What is the result of the following JavaScript code? function outer() { var x = 10;function inner() {console.log(x); }return inner;}var closure = outer();closure();

  • 10 will be logged.
  • An error will occur.
  • "x is not defined" will be logged.
  • "inner" will be logged.

17. What is the purpose of the call() method in JavaScript?

  • To define a loop
  • To create a new object
  • To execute a function with a specified this value and arguments provided individually
  • To create a closure

18. What will be logged to the console in the following JavaScript code? 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

19. 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

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

  • switch
  • case
  • select
  • condition

21. 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

22. 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

23. 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

24. 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

25. 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

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