HTML_CSS_JS_Questions
HTML_CSS_JS_Questions
HTML Questions
Beginner
Q: What does HTML stand for?
A: To provide alternative text for the image if it fails to load or for accessibility.
A: <!DOCTYPE html>
<html>
<head>
<title>Document Title</title>
</head>
<body>
<h1>Welcome to HTML</h1>
</body>
</html>
Intermediate
Q: What is semantic HTML? Provide examples.
A: Semantic HTML uses elements that convey meaning. Examples include <article>,
<section>, <header>, <footer>, <main>.
A: It embeds another HTML document within the current one. Example: <iframe
src="https://example.com" width="600" height="400"></iframe>
Advanced
Q: What is the difference between <script> placed in <head> and <body>?
A: Scripts in <head> load before rendering content, potentially delaying it, while scripts in
<body> execute after content is rendered.
A: It ensures basic functionality works in older browsers while adding advanced features
for newer ones.
A: It allows different images to be loaded based on conditions like screen size or resolution.
A: It does not retain drawing history and is purely pixel-based, making accessibility difficult.
CSS Questions
Beginner
Q: What does CSS stand for?
A: relative positions an element relative to its normal position; absolute positions it relative
to its nearest positioned ancestor.
Q: Write the CSS to change the background color of all <p> tags to blue.
A: p { background-color: blue; }
Intermediate
Q: What are pseudo-classes? Provide examples.
A: Pseudo-classes define the special state of elements. Example: :hover, :focus, :nth-child(n).
A: em is relative to the parent element, while rem is relative to the root element.
A: inline doesn’t start on a new line; block does. inline-block allows inline placement with
block-like properties.
A: It positions elements to the left or right, allowing other content to wrap around it.
Advanced
Q: What is the difference between position: sticky and position: fixed?
A: sticky toggles between relative and fixed based on scroll, while fixed is always relative to
the viewport.
A: visibility: hidden hides the element but keeps space reserved; display: none removes the
element and its space.
A: By using media queries, relative units (%, em, rem), and responsive frameworks like
Bootstrap.
JavaScript Questions
Beginner
Q: What are the data types in JavaScript?
A: var is function-scoped, let and const are block-scoped; const cannot be reassigned.
A: object.
Intermediate
Q: What is the difference between == and ===?
A: == checks for value equality, while === checks for value and type equality.
Q: What is the output of the following code? console.log(0.1 + 0.2 === 0.3);
A: false.
Advanced
Q: Explain the event loop in JavaScript.
A: It handles asynchronous operations by placing callbacks in a queue and executing them
when the call stack is empty.
A: Variables and functions are moved to the top of their scope during compilation.
A: call: Invokes a function with arguments passed individually. apply: Invokes a function
with arguments passed as an array. bind: Returns a new function with a bound context.