HTML & JavaScript Quiz Questions with Answers and Explanations
1. Which operator is used to assign a value to a variable?
Options: =, ==, ===, :=
Answer: =
Explanation: The '=' operator assigns a value to a variable.
2. Which of the following is NOT a JavaScript data type?
Options: string, number, boolean, character
Answer: character
Explanation: JavaScript does not have a 'character' type; it uses strings.
3. What is the result of 2 + "2" in JavaScript?
Options: 4, "22", NaN, undefined
Answer: "22"
Explanation: The number 2 is converted to a string and concatenated.
4. Which keyword declares a constant in JavaScript?
Options: let, const, var, define
Answer: const
Explanation: The 'const' keyword declares a constant variable.
5. Which is the correct way to comment a single line in JavaScript?
Options: # comment, <!-- comment -->, // comment, /* comment */
Answer: // comment
Explanation: '//' is used for single-line comments in JavaScript.
6. What will be the result of typeof NaN?
Options: "number", "NaN", "undefined", "object"
Answer: "number"
Explanation: 'NaN' is still of type number in JavaScript.
7. Which of the following is not a HTML5 tag?
Options: <track>, <video>, <slider>, <source>
Answer: <slider>
Explanation: '<slider>' is not a valid HTML5 tag.
8. Which element is used to get highlighted text in HTML5?
Options: <highlight>, <mark>, <u>, <b>
Answer: <mark>
Explanation: '<mark>' highlights text with yellow by default.
9. In which part of the HTML metadata is contained?
Options: title tag, body tag, head tag, html tag
Answer: head tag
Explanation: Metadata is placed inside the <head> tag.
10. What is DOM in HTML?
Options: Language dependent application programming, Hierarchy of objects in [Link], Application programming interfac
Answer: Convention for representing and interacting with objects in html documents
Explanation: DOM represents HTML as a structured object model.
11. Who is the father of HTML?
Options: N/A
Answer: Tim Berners-Lee
Explanation: He invented HTML and the World Wide Web.
12. Which character is used to represent when a tag is closed in HTML?
Options: #, !, /, \
Answer: /
Explanation: A forward slash '/' is used to close tags.
13. Which HTML tag is used to insert an image?
Options: <img alt="[Link]" />, <img link="[Link]" />, <img src="[Link]" alt="logo" />, <img url="[Link]
Answer: <img src="[Link]" alt="logo" />
Explanation: The 'src' attribute specifies the image path; 'alt' gives alternate text.
14. Which element is used for styling HTML5 layout?
Options: CSS, JQuery, PHP, JavaScript
Answer: CSS
Explanation: CSS is used for styling HTML documents.
15. Which HTML tag is used to convert the plain text into italic format?
Options: <b>, <color>, <font>, <i>
Answer: <i>
Explanation: '<i>' makes text italic.
16. Which of the following elements in HTML5 defines video or movie content?
Options: <video>, <movie>, <audio>, <media>
Answer: <video>
Explanation: '<video>' is used to embed video files.
17. How do we write comments in HTML?
Options: </.......>, <.......................>, <!……>, <…….!>
Answer: <!-- comment -->
Explanation: HTML comments are written as '<!-- comment -->'.
18. What is the correct syntax to output "Hello World" in JavaScript?
Options: print("Hello World"), put("Hello World"), [Link]("Hello World"), printf("Hello World")
Answer: [Link]("Hello World")
Explanation: Use [Link]() to output to the browser console.
19. Which tag is used to create a numbered list in HTML?
Options: <ol>, <li>, <ul>, <ll>
Answer: <ol>
Explanation: '<ol>' creates ordered lists.
20. Which tag is used to create a dropdown in HTML Form?
Options: <input>, <select>, <text>, <textarea>
Answer: <select>
Explanation: '<select>' creates dropdown menus.
21. Which of the following HTML tag is used to create an unordered list?
Options: <ol>, <ul/>, <li>, <ll>
Answer: <ul>
Explanation: '<ul>' creates unordered (bulleted) lists.
22. In HTML, which attribute is used to create a link that opens in a new window/tab?
Options: src="_blank", alt="_blank", target="_blank", target="_self"
Answer: target="_blank"
Explanation: 'target="_blank"' opens links in a new tab.
23. What will [Link](1 + "1" - 1) output?
Options: 1, 10, 11, 12
Answer: 10
Explanation: '1 + "1"' is '11' (string), '11' - 1 = 10.
24. How do you create a function in JavaScript?
Options: function:myFunc(), function = myFunc(), function myFunc(), create function myFunc()
Answer: function myFunc()
Explanation: Correct syntax: function myFunc() { }
25. Inside which HTML element do we put the JavaScript?
Options: <js>, <script>, <code>, <javascript>
Answer: <script>
Explanation: JavaScript code is placed in <script> tags.