Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions advanced.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# JavaScript Interview FAQ — Advanced

Advanced topics and answers for deeper interview prep.

## 1. Event loop internals & rendering
Describe microtask checkpoints, raf (requestAnimationFrame) ordering, and how long tasks block rendering.

## 2. Memory leaks & profiling
Common leaks: listeners not removed, closures holding big objects, forgotten timers. Use Chrome DevTools → Memory tab (heap snapshots, allocation instrumentation).

## 3. Streams (Node & Web)
Readable/Writable/Transform streams, piping, backpressure handling, and when to use streams vs buffering.

## 4. Node event loop & worker threads
Phases of Node event loop, libuv threadpool, difference between worker threads and child processes.

## 5. Module systems, static analysis, tree-shaking
ESM supports static imports enabling tree-shaking; CommonJS is dynamic and synchronous.

## 6. Security basics (XSS, CSP)
XSS types (reflected, stored, DOM), sanitize inputs, use Content Security Policy to mitigate inline-script risks.

## 7. Performance: repaint/reflow & layout thrashing
Batch DOM reads and writes, avoid forced synchronous layouts, use `requestAnimationFrame` for animation updates.

## 8. WeakMap / WeakRef use-cases
WeakMap for metadata on objects without preventing GC; WeakRef for caching with ephemeral references (use carefully).

## 9. Advanced ES features: proxies, symbols, decorators (stage)
Use-cases for proxy traps, customizing iteration with symbols, decorators for meta-programming (proposal stage changes).

## 10. Concurrency patterns: atomicity & locking (worker patterns)
Use worker threads / web workers for CPU heavy tasks, message-passing for shared-nothing concurrency, Atomics + SharedArrayBuffer for low-level sync.
33 changes: 33 additions & 0 deletions basic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# JavaScript Interview FAQ — Basic

A compact set of common JavaScript interview questions with concise answers.

## 1. What is the event loop? How does it handle asynchronous callbacks?
The event loop checks the call stack; when empty it drains microtasks (promises) then runs one macrotask (e.g., `setTimeout`) and repeats.

## 2. Difference between `var`, `let`, and `const`
`var` is function-scoped and hoisted; `let`/`const` are block-scoped. `const` can't be reassigned.

## 3. Explain closures
A closure is a function that retains access to its lexical scope even when executed elsewhere — useful for private state.

## 4. `==` vs `===`
`==` coerces types before comparing; `===` is strict (no coercion).

## 5. How `this` is determined in JS?
Determined by call-site: default/global, object method (implicit), explicit (`call`/`apply`), `new`, or lexical for arrow functions.

## 6. Prototype vs class
`class` is syntax sugar over prototype-based inheritance. Objects inherit via the prototype chain.

## 7. Call, apply, bind
`call(thisArg, ...)`, `apply(thisArg, [args])` invoke immediately; `bind(thisArg)` returns a bound function.

## 8. Promises vs async/await
Promises represent eventual results; `async/await` is syntactic sugar for working with promises.

## 9. Microtasks vs Macrotasks
Microtasks (promises) run after the current stack but before the next macrotask (timers, I/O).

## 10. Hoisting
Function and `var` declarations are hoisted. `let`/`const` are hoisted but in TDZ until initialized.