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

  • A programming language used for creating dynamic web pages
  • A style sheet language for web development
  • A markup language for structuring web content
  • A database management system

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

  • var
  • variable
  • v
  • int

3. How do you write a single-line comment in JavaScript?

  • // This is a comment
  • <!-- This is a comment -->
  • /* This is a comment */
  • # This is a comment

4. What is the purpose of the `typeof` operator in JavaScript?

  • It converts a value to a different data type
  • It checks the type of a value
  • It performs arithmetic operations
  • It defines a new variable

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

  • String
  • Integer
  • Object
  • Boolean

6. What will the following code output. `console.log(5 + '5')`?

  • 10
  • 55
  • 25
  • Error

7. Which function is used to display a message in a popup dialog box in JavaScript?

  • alert()
  • display()
  • message()
  • popup()

8. What does the `null` value represent in JavaScript?

  • An empty string
  • A missing or non-existent value
  • A zero value
  • An undefined value

9. What does the `===` operator do in JavaScript?

  • It assigns a value to a variable
  • It checks for equality without type coercion
  • It performs addition
  • It concatenates strings

10. How do you create a function in JavaScript?

  • func myFunction() {}
  • function. myFunction() {}
  • def myFunction() {}
  • function myFunction() {}

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

  • for loop
  • while loop
  • do-while loop
  • for...in loop

12. What is the purpose of the `return` statement in a JavaScript function?

  • It defines a variable
  • It repeats a loop
  • It ends the function and returns a value
  • It comments out code

13. Which of the following is true about JavaScript's "hoisting"?

  • Variables are moved to the top of their scope during compilation
  • Variables are only accessible within the function where they are declared
  • Variables are automatically initialized to zero
  • Hoisting is not a concept in JavaScript

14. What is the purpose of the `this` keyword in JavaScript?

  • It refers to the next function to be executed
  • It refers to the current function
  • It refers to the object that is executing the current function
  • It refers to the global object

15. How can you add a comment that spans multiple lines in JavaScript?

  • /* This is a comment */
  • // This is a comment
  • <!-- This is a comment -->
  • # This is a comment

16. Which built-in object in JavaScript represents the global context?

  • Window
  • Document
  • Global
  • Context

17. What does the `parseFloat()` function do in JavaScript?

  • It converts a string to a floating-point number
  • It parses an integer
  • It checks if a variable is undefined
  • It rounds a number to the nearest integer

18. How do you add an element to the end of an array in JavaScript?

  • array.add(element)
  • array.append(element)
  • array.push(element)
  • array.concat(element)

19. Which operator is used to concatenate strings in JavaScript?

  • +
  • &
  • +
  • .

20. What is the purpose of the `new` keyword in JavaScript?

  • It creates a new variable
  • It creates a new function
  • It creates a new object
  • It defines a new condition

21. Which function is used to remove the last element from an array in JavaScript?

  • array.pop()
  • array.shift()
  • array.removeLast()
  • array.splice()

22. What is the purpose of the `JSON.parse()` function in JavaScript?

  • It parses a JSON string and returns an object
  • It creates a new JSON string
  • It converts a number to a string
  • It checks for syntax errors in JavaScript code

23. Which function is used to find the length of a string in JavaScript?

  • string.len()
  • string.count()
  • string.length
  • string.size()

24. How do you declare a constant variable in JavaScript?

  • const myVar
  • let myVar
  • var myVar
  • constant myVar

25. Which built-in object represents the browser's Document Object Model (DOM) in JavaScript?

  • DOMObject
  • DOMElement
  • document
  • DOMModel

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