Interview Cheatsheet

πŸ“„ HTML Basics

Semantic HTML Tags

Tag Purpose
<header> Introductory content, site branding, navigation
<nav> Major navigation links
<main> Main unique content (one per page)
<article> Self-contained content (blog post, comment)
<section> Thematic grouping of related content
<aside> Sidebar, related links, supplementary info
<footer> Page footer, copyright, related links
<figure> Self-contained illustration, diagram, photo
<figcaption> Caption for <figure>

Web Accessibility (a11y)

Key Principles

  • Perceivable: Content must be perceivable by users
  • Operable: Navigation via keyboard, no keyboard traps
  • Understandable: Content is clear and readable
  • Robust: Works with assistive technologies

Accessibility Checklist

  • alt text on all images
  • Proper heading hierarchy (h1 β†’ h6)
  • Form labels with <label> tags
  • aria-label for icon buttons
  • role attributes for custom components
  • Color contrast ratio β‰₯ 4.5:1
  • Keyboard navigation support
  • Focus indicators visible

HTML Forms

Input Type Description
text Single-line text input
password Password input (masked)
email Email address input with validation
number Numeric input with optional min/max
checkbox Multiple selection options
radio Single selection from a group
submit Submit the form data

Remember to use the correct form attributes like:

  • action: URL to send form data to
  • method: GET or POST for data submission

HTML5 New Features

  • New Semantic Elements: <header>, <footer>, <article>, <section>, <nav>
  • Audio and Video: <audio>, <video> tags for media playback
  • Canvas: <canvas> for drawing graphics via JavaScript
  • Local Storage: Web Storage API for storing data in the browser
  • Geolocation API: Access user's location with permission
  • Form Enhancements: New input types, validation, and attributes

Flashcards β€” HTML

What is the purpose of a semantic tag?
It gives meaning to content and improves accessibility and SEO.
Why is alt text important?
It helps screen readers describe images and improves accessibility.
What does ARIA help with?
It helps make custom UI components more accessible to assistive technologies.
Why use <section> instead of <div>?
A <div> is a generic container with no semantic meaning, while <section> groups related content that usually has a heading and gives structure to the page.
What is the difference between <article> and <section>?
An <article> is a self-contained piece of content that should still make sense on its own, while a <section> groups related content under a common theme.
What is <span> used for?
A <span> is an inline element mainly used to style or target part of a sentence or word without breaking the flow of text.
🟨 JavaScript (ES6+)

Async/Await vs Promises

PromisesAsync/Await
Chainable with .then/.catchSyntactic sugar over Promises, reads like sync code
Good for parallel flows (Promise.all)Good for sequential flows and readability
Must handle rejections with .catchUse try/catch for errors
Works in older environments with polyfillsRequires async-capable runtime or transpile
// create 23 promises and await them
const tasks = Array.from({length:23}, (_,i) =>
  new Promise((res) => setTimeout(() => res(i+1), 10 + (i%5)*10))
);

// parallel with Promise.all
Promise.all(tasks).then(results => console.log('parallel results', results));

// sequential with async/await
async function runSequential(){
  const out = [];
  for(const t of tasks){
    out.push(await t);
  }
  console.log('sequential results', out);
}
runSequential();

Arrow Functions

Shorter syntax; lexical `this` binding.

const nums = [1,2,3];
const squares = nums.map(n => n*n);
const obj = {
  val: 10,
  getVal: () => this.val // `this` is lexical, not the object
};

let / const & Block Scope

`let` and `const` are block-scoped; `const` is immutable binding.

for(let i=0;i<3;i++){
  setTimeout(()=>console.log(i), 10); // prints 0,1,2
}
const a = {x:1};
a.x = 2; // allowed; binding immutable, properties mutable

Destructuring & Defaults

const [a,b=2] = [1];
const {name='anon'} = {};
function f({x=0,y=0} = {}){ return x+y }

Spread & Rest

const a = [1,2];
const b = [...a,3];
function sum(...nums){ return nums.reduce((s,n)=>s+n,0) }

Modules (import / export)

// module.js
export function add(a,b){ return a+b }

// main.js
import { add } from './module.js';
console.log(add(1,2));

Browser Storage

Use localStorage for data that should persist across browser sessions, and sessionStorage for temporary data that should disappear when the tab closes.

localStorage.setItem('theme', 'dark');
const theme = localStorage.getItem('theme');

sessionStorage.setItem('step', '2');

Classes & Prototypes

class Animal{ constructor(name){ this.name = name } speak(){ return this.name } }
class Dog extends Animal{ bark(){ return 'woof' }}
const d = new Dog('Fido');

Map / Set

const s = new Set([1,2,2]);
const m = new Map([['k', 'v']]);
console.log(s.has(1), m.get('k'));

Generators & Iterators

function* gen(){ yield 1; yield 2 }
const it = gen();
console.log(it.next().value);

Flashcards β€” JavaScript

Promise vs async/await: main difference?
async/await is syntactic sugar over Promises, making async code look synchronous; Promises provide methods like .then/.catch.
How do you handle multiple promises in parallel?
Use Promise.all (or Promise.allSettled) to run promises in parallel and await their combined result.
What is a closure?
A function that retains access to the lexical scope in which it was created, even after that scope has exited.
Explain event loop microtasks vs macrotasks.
Microtasks (Promises) run after the current task but before the next rendering; macrotasks (setTimeout) run later in the queue.
Difference between == and ===?
== performs type coercion before comparison; === checks strict equality without coercion.
What's lexical `this` in arrow functions?
Arrow functions do not have their own `this`; they inherit `this` from the surrounding lexical scope.
When to use Map vs Object?
Map preserves insertion order, accepts any key types, and has size propertyβ€”better for keyed collections than plain objects.
What are generators good for?
Generators allow pausing/resuming function execution and are useful for lazy sequences and implementing iterators.
How do modules differ from CommonJS require?
ES modules are statically analyzable and use `import`/`export`; CommonJS loads modules at runtime with `require`.
What is the difference between let, const, and var?
`var` is function-scoped and hoisted; `let` and `const` are block-scoped, with `const` being immutable binding.
What is the difference between null and undefined?
`undefined` means a variable has been declared but not assigned; `null` is an assignment value representing no value.
What is the difference between synchronous and asynchronous code?
Synchronous code runs sequentially, blocking further execution until complete; asynchronous code allows other operations to run while waiting for tasks to finish.
What is the difference between synchronous and asynchronous code?
Synchronous code runs sequentially, blocking further execution until complete; asynchronous code allows other operations to run while waiting for tasks to finish.
πŸ’» CSS Basics

CSS Box Model

The CSS box model describes the rectangular boxes generated for elements in the document tree and consists of:

  • Content: The actual content of the box, where text and images appear.
  • Padding: Clears an area around the content. The padding is transparent.
  • Border: A border that goes around the padding (if any) and content.
  • Margin: Clears an area outside the border. The margin is also transparent.
<div class="box-container">
  <div class="box">1</div>
  <div class="box">2</div>
  <!-- repeat for 23 boxes -->
</div>

.box-container { padding: 12px; border: 2px solid #1976d2; }
.box { width: 32px; height: 32px; margin: 4px; padding: 6px; border: 2px solid #1565c0; }

CSS Flexbox

Flexbox is a one-dimensional layout method for arranging items in rows or columns. Key properties include:

  • display: flex; - Defines a flex container.
  • flex-direction: - Row or column layout.
  • justify-content: - Aligns items horizontally.
  • align-items: - Aligns items vertically.
  • flex-wrap: - Allows items to wrap onto multiple lines.
<div class="flex-demo">
  <div class="box">1</div>
  <div class="box">2</div>
  <!-- repeat for 23 boxes -->
</div>

.flex-demo {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

CSS Grid

CSS Grid is a two-dimensional layout system for creating complex layouts. Key properties include:

  • display: grid; - Defines a grid container.
  • grid-template-columns / grid-template-rows: - Defines the columns and rows of the grid.
  • grid-gap: - Sets the gap between rows and columns.
  • grid-column / grid-row: - Specifies how many columns or rows an item should span.
  • justify-items / align-items: - Aligns items within their grid area.
<div class="grid-demo">
  <div class="box">1</div>
  <div class="box">2</div>
  <!-- repeat for 23 boxes -->
</div>

.grid-demo {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}

Flashcards β€” CSS

What are the four parts of the box model?
Content, padding, border, and margin.
What is Flexbox best for?
Laying out items in one dimension, either rows or columns.
What is CSS Grid best for?
Creating two-dimensional layouts with rows and columns.
What does justify-content do in Flexbox?
It aligns items along the main axis (horizontally in a row, vertically in a column).
What does align-items do in Flexbox?
It aligns items along the cross axis (vertically in a row, horizontally in a column).
What is the difference between inline, block, and inline-block elements?
Inline elements do not start on a new line and only take up as much width as necessary. Block elements start on a new line and take up the full width available. Inline-block elements are like inline elements but can have width and height set.
βš›οΈ React

React Render Cycle

User action
⬇
setState() / dispatch() / Context changes
⬇
Component renders again
⬇
Virtual DOM comparison
⬇
DOM updated
⬇
Browser Paint
⬇
useEffect()

React vs Vanilla JavaScript

Vanilla JavaScript manipulates the DOM directly with methods like querySelector and addEventListener. React lets you describe the UI declaratively with components and state, and it updates the DOM efficiently when state changes.

When should you use useEffect?

Dependency Runs when...
[] Only once after mount
[count] Whenever count changes
[user] Whenever context/state reference changes
No dependency array After EVERY render

Triggers Re-render?

Action Re-render?
setState() βœ” Yes
dispatch() βœ” Yes
Context Provider changes βœ” Yes
Props change βœ” Yes
useEffect() ✘ No*

* Unless the effect itself calls setState().

Use useEffect for side effects such as fetching data, subscribing to events, timers, or syncing with browser APIs like localStorage. It is usually not the right tool for computing values from existing state during render.

Context vs Reducer

Context Reducer
Shares state Updates state
Avoids prop drilling Centralizes logic
Who can access? How does it change?

Props: Parent to Child

A parent component can own state and pass both values and callback functions to children through props. This is a common pattern for controlling behavior from a parent.

function Parent() {
  const [count, setCount] = useState(0);

  const handleReset = () => setCount(0);

  return (
    

Count: {count}

); } function Child({ count, onReset }) { return ; }

Class vs Functional Components

Class Component Functional Component
Uses lifecycle methods Uses hooks
Has this.state and this.setState() Uses useState() hook
More boilerplate code Simpler and more concise

useContext

useContext lets a component read values from a context without passing props through every level. It is helpful for shared data such as themes, authentication, or user settings.

const ThemeContext = createContext();

function ThemeProvider({ children }) {
  const [theme, setTheme] = useState('light');

  return (
    
      {children}
    
  );
}

function Header() {
  const { theme } = useContext(ThemeContext);
  return 

Current theme: {theme}

; }

Flashcards β€” React

What triggers a React re-render?
State changes, prop changes, and context updates typically trigger re-renders.
How is React different from vanilla JavaScript?
Vanilla JavaScript manipulates the DOM directly, while React uses declarative components and state to update the DOM efficiently.
When should you use useEffect?
Use it for side effects such as fetching data, subscriptions, timers, and browser API synchronization.
When would you choose props over useContext?
Use props for simple, direct data flow between a parent and a child. Use useContext for shared values that many components need without threading props through every level.
When does useEffect run?
After the component renders, and again when its dependencies change.
What is the difference between context and reducer?
Context shares state, while a reducer centralizes how state changes.
What is the main difference between class and functional components?
Class components use lifecycle methods and this.state; functional components use hooks and are usually simpler.
When would you choose a functional component over a class component?
Functional components are preferred for modern React when you want simpler logic and hooks-based state/effects.
What is the purpose of a key prop in a list?
It helps React identify which list items changed, were added, or removed, improving reconciliation.
What is the difference between controlled and uncontrolled components?
Controlled components have their state managed by React, while uncontrolled components manage their own state internally.
What is the difference between useState and useReducer?
useState is for simple state management, while useReducer is better for complex state logic and multiple state transitions.
What is the difference between useEffect and useLayoutEffect?
useEffect runs after the render is committed to the screen, while useLayoutEffect runs synchronously after all DOM mutations but before the browser paints.
What is the difference between React.memo and useMemo?
React.memo is a higher-order component that memoizes a component to prevent unnecessary re-renders, while useMemo is a hook that memoizes a value or computation within a component.
πŸ…°οΈ Angular

Angular Architecture

  • Components: UI building blocks with templates and logic.
  • Modules: Group related features and declarations.
  • Services: Shared logic, data access, and cross-component state.
  • Dependency Injection: Angular injects dependencies where needed.

Data Binding

Angular supports several binding types:

  • Interpolation: {{ value }}
  • Property binding: [src]="imageUrl"
  • Event binding: (click)="save()"
  • Two-way binding: [(ngModel)]
@Component({
  template: `<h2>{{ title }}</h2>`
})
export class DemoComponent {
  title = 'Angular';
}

Services & Dependency Injection

Services centralize reusable logic and are injected into components via Angular's DI container.

@Injectable({ providedIn: 'root' })
export class UserService {
  getUsers() { return ['Ada', 'Grace']; }
}

RxJS & Observables

RxJS lets Angular handle asynchronous streams with observables, operators, and subscriptions.

this.http.get<User[]>('/api/users').subscribe(users => {
  this.users = users;
});

Change Detection

Angular updates the UI based on change detection. Using ChangeDetectionStrategy.OnPush can improve performance by limiting checks.

@Component({
  selector: 'app-card',
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: '

{{ name }}

' }) export class CardComponent { @Input() name = ''; }

Flashcards β€” Angular

What are Angular components responsible for?
They define the UI, behavior, and template for a specific part of the application.
What is dependency injection in Angular?
It is a design pattern where Angular provides dependencies to classes instead of having them create them manually.
What is the difference between interpolation and property binding?
Interpolation renders values into text, while property binding updates DOM properties such as src or disabled.
What are services used for?
Services are used to share logic, data access, and business rules across multiple components.
What is RxJS commonly used for in Angular?
It handles asynchronous data streams, HTTP requests, events, and reactive programming.
What does OnPush change detection do?
It reduces unnecessary checks by only updating the component when its inputs or events change.
node.js
Event Loop
⬇
Call Stack
⬇
Node APIs (fs, http, etc.)
⬇
Callback Queue
⬇
Microtask Queue (Promises)

Node.js Event Loop

The Node.js event loop is a mechanism that allows Node.js to perform non-blocking I/O operations by offloading operations to the system kernel whenever possible.

  • Phases: Timers, I/O callbacks, idle/prepare, poll, check, close callbacks.
  • Microtasks: Promises and process.nextTick are executed after the current operation completes but before the event loop continues.
  • Non-blocking: Node.js uses an event-driven architecture to handle multiple connections concurrently without blocking the main thread.

Node.js Modules

Node.js uses the CommonJS module system, where each file is treated as a separate module.

  • require: Used to import modules.
  • module.exports: Used to export functions, objects, or values from a module.
  • ES Modules: Node.js also supports ES6 modules using import and export, but it requires the use of the .mjs extension or setting "type": "module" in package.json.

Node.js Streams

Streams are a way to handle reading/writing data in chunks, which is efficient for large data sets.

  • Readable Streams: Used for reading data (e.g., fs.createReadStream).
  • Writable Streams: Used for writing data (e.g., fs.createWriteStream).
  • Duplex Streams: Can be both readable and writable (e.g., net.Socket).
  • Transform Streams: A type of duplex stream that can modify or transform the data as it is read or written.