0% found this document useful (0 votes)
14 views3 pages

HTML & JavaScript Quiz with Answers

The document contains a series of HTML and JavaScript quiz questions along with their answers and explanations. It covers various topics including data types, operators, HTML tags, and JavaScript functions. Each question is designed to test knowledge of web development concepts and syntax.

Uploaded by

jyoshnairigala
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views3 pages

HTML & JavaScript Quiz with Answers

The document contains a series of HTML and JavaScript quiz questions along with their answers and explanations. It covers various topics including data types, operators, HTML tags, and JavaScript functions. Each question is designed to test knowledge of web development concepts and syntax.

Uploaded by

jyoshnairigala
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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.

Common questions

Powered by AI

'NaN' stands for Not-a-Number, but it is considered a number in JavaScript because it is a specific numeric value that represents an undefined or unrepresentable result in calculations. The typeof operator confirms this as it returns "number" for NaN. This is because NaN is codified in the ECMAScript standard as being of type number . It can be verified programmatically using the expression typeof NaN, which returns "number", or by checking with the function Number.isNaN() that accurately identifies if a value is NaN.

JavaScript performs type coercion by converting one of the operands to the type of the other. In the case of the operation 2 + "2", the number 2 is converted to a string and concatenated, resulting in the string "22". This occurs because when a number and a string are added using the '+' operator, JavaScript prefers string concatenation. However, in the operation console.log(1 + "1" - 1), "1" is initially coerced to "11" as a string during addition, but the subtraction operator then converts "11" back to a number, yielding 10 .

An ordered list in HTML is created using the '<ol>' tag, which automatically numbers the list items, indicating a specific sequence. An unordered list, created using '<ul>', does not imply any sequence and typically uses bullet points for each item. The choice between the two depends on whether the order of items carries significance. Ordered lists are preferred in contexts where the sequence matters, such as instructions or rankings, while unordered lists are used when the order is irrelevant, like listing features of a product .

Metadata within the '<head>' tag includes titles, descriptions, and keywords which play a significant role in SEO by informing search engines about the content and context of the webpage. Properly structured metadata can enhance search visibility and relevance, thereby potentially increasing traffic. Additionally, metadata can influence web performance through the inclusion of link tags for preloading resources and specifying character sets which streamline browser processing. However, excessive or mismanaged metadata can have the opposite effect, leading to reduced performance .

The '<mark>' tag is used to highlight parts of a document for emphasis, typically rendering text with a yellow background by default. From a semantic perspective, it indicates relevance or highlights specific information useful to the user, improving readability and conveying immediacy within the context. Such highlighted sections can assist in drawing the user's attention to important parts of the content without dramatically altering the document's semantics, thus maintaining its structural integrity .

Secure initialization and management of variables and constants in JavaScript can be achieved by following practices such as choosing appropriate scoping keywords ('let' and 'const' for block scoping), initializing variables as close to their first use as possible, enforcing immutability through 'const' where reassignment is not required, and employing ESLint or similar tools to enforce coding standards and identify potential security issues. Additionally, leveraging module patterns or encapsulating code within closures helps avoid unintentional global variable creation, thereby safeguarding data integrity across scopes .

The use of 'target="_blank"' in anchor tags causes links to open in a new browser window or tab, which can be beneficial for user navigation but poses security risks like 'tabnapping'. This occurs when the target page manipulates the original page in a way that the user is unaware of the change. To mitigate this risk, the 'rel="noopener noreferrer"' attribute is recommended alongside 'target="_blank"' to ensure the original page is protected from potential security threats. Additionally, continually spawning new windows can impair accessibility for users relying on assistive technologies .

Constants in JavaScript are declared using the 'const' keyword, which differs from 'let' and 'var' in that once a constant is assigned a value, it cannot be reassigned. This provides immutability to their values post-initialization. In contrast, variables declared with 'let' and 'var' can have their values changed. Additionally, 'const' does not allow re-declaration within the same scope, similar to 'let', and differs from 'var', which does allow re-declaration .

CSS is the preferred tool for styling HTML layouts due to its design specificity, separation of content from presentation, and ability to control the visual representation across multiple pages consistently with minimal effort. It allows for improved design flexibility, layout control, and responsiveness compared to other scripting languages like JavaScript or PHP which focus more on dynamic behaviors and backend processing. CSS techniques enable designers to implement responsive designs that adapt to various devices and screen sizes efficiently .

The Document Object Model (DOM) allows HTML documents to be represented as a structured tree of objects. This structure enables scripts and programs to dynamically access and update the content, structure, and style of documents, offering a powerful method for creating and controlling web-based applications. Using the DOM, developers can modify page elements without needing to reload the entire page, thus improving the performance and user experience of web applications .

You might also like