Interview Preparation
Prepare for technical interviews with curated questions and detailed answers.
HTML Interview Questions
3 questionsWhat is the difference between HTML elements and HTML tags?
Show answer
HTML elements and tags are related but different concepts: **HTML Tags:** These are the markup symbols that define the start and end of an element. For example, <p> and </p> are tags. **HTML Elements:** An element consists of the opening tag, content, and closing tag together. For example, <p>This is a paragraph</p> is a complete paragraph element. In summary: - Tags are the markup (<p>, </p>) - Elements are the complete structure (tags + content)
Likely follow-up questions
- Can you name some self-closing HTML tags?
- What happens if you forget to close an HTML tag?
Explain the difference between <div> and <span> elements.
Show answerincludes code
<div> and <span> are both generic container elements, but they have different display behaviors: **<div> (Division):** - Block-level element - Takes up the full width available - Starts on a new line - Used for larger sections of content - Can contain other block and inline elements **<span>:** - Inline element - Only takes up as much width as necessary - Does not start on a new line - Used for small portions of content within other elements - Should only contain inline elements Example:
<div>This is a block-level div element</div>
<div>This is another div on a new line</div>
<p>This is a paragraph with a <span>highlighted span</span> inside.</p>Likely follow-up questions
- How can you change a div to behave like an inline element?
- What are semantic alternatives to div and span?
What are semantic HTML elements and why are they important?
Show answerincludes code
Semantic HTML elements are HTML tags that provide meaning to the content they contain, beyond just presentation. They describe the structure and purpose of content. **Examples of semantic elements:** - <header> - Page or section header - <nav> - Navigation links - <main> - Main content area - <section> - Thematic grouping of content - <article> - Independent, self-contained content - <aside> - Content aside from main content - <footer> - Page or section footer **Why they're important:** 1. **Accessibility:** Screen readers and assistive technologies understand the structure better 2. **SEO:** Search engines better understand your content structure 3. **Code readability:** Makes code more maintainable and understandable 4. **Future-proofing:** Better support for new technologies and devices **Example:**
<article>
<header>
<h1>Article Title</h1>
<time datetime="2024-01-15">January 15, 2024</time>
</header>
<section>
<h2>Introduction</h2>
<p>Article content...</p>
</section>
<aside>
<h3>Related Links</h3>
<ul>
<li><a href="#">Related Article</a></li>
</ul>
</aside>
<footer>
<p>Author: John Doe</p>
</footer>
</article>Likely follow-up questions
- How do semantic elements help with SEO?
- What's the difference between <section> and <div>?
CSS Interview Questions
2 questionsExplain the CSS Box Model.
Show answerincludes code
The CSS Box Model describes how elements are structured and how their dimensions are calculated. Every element is essentially a rectangular box consisting of four areas: **From inside to outside:** 1. **Content:** The actual content (text, images, etc.) 2. **Padding:** Space between content and border (transparent) 3. **Border:** The border around the padding and content 4. **Margin:** Space outside the border (transparent) **Box-sizing property:** - `box-sizing: content-box` (default): Width/height applies only to content - `box-sizing: border-box`: Width/height includes padding and border **Example:**
.box {
width: 200px;
height: 100px;
padding: 20px;
border: 5px solid black;
margin: 10px;
/* Total width = 200 + 20*2 + 5*2 + 10*2 = 270px */
}
.box-border-box {
box-sizing: border-box;
width: 200px; /* Total width will be exactly 200px */
padding: 20px;
border: 5px solid black;
}Likely follow-up questions
- What's the difference between margin and padding?
- How does box-sizing: border-box affect calculations?
What is CSS specificity and how does it work?
Show answerincludes code
CSS specificity determines which styles are applied when multiple rules target the same element. It's calculated based on the types of selectors used. **Specificity hierarchy (from highest to lowest):** 1. **Inline styles** (style="...") - 1000 points 2. **IDs** (#myId) - 100 points each 3. **Classes, attributes, pseudo-classes** (.class, [attr], :hover) - 10 points each 4. **Elements and pseudo-elements** (div, p, ::before) - 1 point each **Important rules:** - `!important` overrides normal specificity - Later rules with same specificity override earlier ones - Inherited styles have no specificity **Examples:**
/* Specificity: 0,0,0,1 (1 point) */
p { color: blue; }
/* Specificity: 0,0,1,1 (11 points) */
p.highlight { color: red; }
/* Specificity: 0,1,0,1 (101 points) */
#content p { color: green; }
/* Specificity: 1,0,0,0 (1000 points) */
/* <p style="color: purple;">Text</p> */
/* Overrides everything */
p { color: orange !important; }Likely follow-up questions
- How can you avoid specificity conflicts?
- What happens when two rules have the same specificity?
JavaScript Interview Questions
2 questionsExplain hoisting in JavaScript.
Show answerincludes code
Hoisting is JavaScript's behavior of moving variable and function declarations to the top of their scope during compilation, before code execution. **Variable Hoisting:** - `var` declarations are hoisted and initialized with `undefined` - `let` and `const` are hoisted but not initialized (Temporal Dead Zone) - `function` declarations are fully hoisted **Examples:**
// Variable hoisting with var
console.log(myVar); // undefined (not ReferenceError)
var myVar = 5;
// Equivalent to:
var myVar; // hoisted declaration
console.log(myVar); // undefined
myVar = 5; // assignment stays in place
// let/const hoisting (Temporal Dead Zone)
console.log(myLet); // ReferenceError: Cannot access before initialization
let myLet = 10;
// Function hoisting
sayHello(); // "Hello!" - works because function is hoisted
function sayHello() {
console.log("Hello!");
}
// Function expressions are NOT hoisted
sayGoodbye(); // TypeError: sayGoodbye is not a function
var sayGoodbye = function() {
console.log("Goodbye!");
};Likely follow-up questions
- What is the Temporal Dead Zone?
- How does hoisting work with function expressions vs function declarations?
What is the difference between == and === in JavaScript?
Show answerincludes code
The difference between == and === relates to type conversion: **== (Loose equality):** - Performs type coercion before comparison - Converts operands to the same type, then compares - Can lead to unexpected results **=== (Strict equality):** - No type coercion - Compares both value and type - Recommended for most use cases **Examples:**
// Loose equality (==) with type coercion
5 == "5" // true (string "5" converted to number)
true == 1 // true (boolean converted to number)
false == 0 // true
null == undefined // true
"" == 0 // true (empty string converted to 0)
// Strict equality (===) without type coercion
5 === "5" // false (different types)
true === 1 // false (different types)
false === 0 // false (different types)
null === undefined // false (different types)
"" === 0 // false (different types)
// Same type comparisons work the same way
5 === 5 // true
"hello" === "hello" // true
// Special cases
NaN === NaN // false (NaN is not equal to anything, including itself)
Object.is(NaN, NaN) // true (more reliable equality check)Likely follow-up questions
- When might you want to use == instead of ===?
- How does Object.is() differ from ===?
Before the Interview:
- • Review fundamental concepts thoroughly
- • Practice coding problems on paper
- • Prepare questions about the company
- • Review your past projects
- • Practice explaining complex concepts simply
During the Interview:
- • Think out loud while solving problems
- • Ask clarifying questions
- • Start with a simple solution, then optimize
- • Admit when you don't know something
- • Show enthusiasm for learning
Technical Screen
Phone or video call focusing on technical knowledge and coding problems.
Coding Challenge
Live coding session where you solve problems while explaining your approach.
System Design
High-level architecture discussion for building scalable applications.