Skip to content
Merged
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
30 changes: 15 additions & 15 deletions blog/2025-08-13-interview-tips-2025-8.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,41 @@ hide_table_of_contents: false
## JavaScript Core

1) What is a closure?
- A closure is a function that remembers its outer scope via the **lexical environment**, even after the outer function returns.
- If asked: It keeps access to variables where it was created. Example: `function outer(){ let x=1; return function(){ console.log(x) } }`.
- A closure is a function that remembers its outer scope via the **lexical environment(词法环境)**, even after the outer function returns.
- If asked: It keeps access to variables where it was created.

2) Hoisting in JavaScript?
- **Declarations** are moved to the top; **var** hoists with undefined, **let/const** hoist but stay in **TDZ**.
- If asked: `var` is usable before line but is `undefined`. `let/const` throw if used before declared. Example: `console.log(a); var a=1;` vs `console.log(b); let b=1;`.
- If asked: `var` is usable before line but is `undefined`. `let/const` throw if used before declared.

3) How does “this” work?
- **this** depends on **call site**: default, **method**, **call/apply/bind**, **new**, or **arrow** (lexical).
- **this** depends on **call site(调用点)**: default, **method**, **call/apply/bind**, **new**, or **arrow** (lexical).
<!-- truncate -->
- If asked: In a method, `this` is the object. With `call/apply/bind`, you set it. Arrow uses the outer `this`. Example: `obj.fn()` vs `fn.call(obj)`.
- If asked: In a method, `this` is the object. With `call/apply/bind`, you set it. Arrow uses the outer `this`.

4) Prototype vs class?
- **Prototype chain** is native inheritance; **class** is syntax sugar over prototypes.
- If asked: `class` makes prototype code look cleaner. Under the hood it still uses prototypes. Example: `class A{}` ≈ function + `A.prototype`.
- If asked: `class` makes prototype code look cleaner. Under the hood it still uses prototypes.

5) Event loop basics?
- JS is **single-threaded**; **event loop** runs **call stack**, then **microtasks** (Promises), then **macrotasks**.
- If asked: Promises run before timers in the same tick. Example order: sync → microtasks → timers.

6) Promise vs async/await?
- **Promises** model async; **async/await** is syntax for **sequential** style with **try/catch**.
- If asked: `await` pauses inside async function. Use `try/catch` for errors. Example: `const x = await fetch()`.
- **Promises** model async; **async/await** is syntax for **sequential(顺序的)** style with **try/catch**.
- If asked: `await` pauses inside async function. Use `try/catch` for errors.

7) Debounce vs throttle?
- **Debounce** waits for silence; **Throttle** limits calls to a **rate**.
- **Debounce(延迟)** waits for silence; **Throttle(节流)** limits calls to a **rate**.
- If asked: Debounce: run after user stops typing. Throttle: run at most once per 100ms while scrolling.

8) == vs ===?
- **===** checks **type + value**; **==** does **coercion** (avoid unless sure).
- **===(Strict Equality)** checks **type + value**; **==(Loose Equality)** does **implicit type conversion**.
- If asked: `0 == false` is true; `0 === false` is false. Prefer `===` to avoid surprises.

9) var vs let vs const?
- **var** is **function-scoped**; **let/const** are **block-scoped**; **const** blocks **reassignment**.
- If asked: Use `const` by default, `let` when you reassign, avoid `var`. Blocks are `{ ... }`.
- If asked: Use `const` by default, `let` when you reassign, avoid `var`.

10) Arrow function differences?
- **Arrow** has **lexical this**, no **arguments**, not **constructible**.
Expand All @@ -62,7 +62,7 @@ hide_table_of_contents: false

14) Immutable data—why?
- **Immutability** reduces **side effects**, helps **debugging**/**change detection**.
- If asked: Don’t modify input. Return new arrays/objects. Example: `const b = a.map(x=>x)`.
- If asked: Don’t modify input. Return new arrays/objects.

15) Module systems: CommonJS vs ES Modules?
- **CommonJS** is **sync** (Node legacy); **ESM** is **static**, supports **tree-shaking**.
Expand Down Expand Up @@ -180,7 +180,7 @@ hide_table_of_contents: false
- If asked: Use workers for CPU heavy tasks (hashing). Use cluster to use many CPU cores for HTTP.

43) child_process use cases?
- Run **shell commands**, **spawn** tools, offload work; manage **stdout/stderr**/**exit codes**.
- Run **shell commands**, **spawn(衍生)** tools, offload work; manage **stdout/stderr**/**exit codes**.
- If asked: Example: `exec('ls -la', cb)`; `spawn` for streaming output.

44) Express middleware order?
Expand All @@ -192,7 +192,7 @@ hide_table_of_contents: false
- If asked: Keep `.env` out of git. In cloud, use managed secret stores.

46) Logging best practices?
- **Structured logs** (JSON), **correlation IDs**, **levels**, avoid **PII**.
- **Structured logs** (JSON), **correlation(相关性) IDs**, **levels**, avoid **PII**.
- If asked: Include `requestId` in each log line to trace a request.

47) Securing a Node API?
Expand Down Expand Up @@ -221,7 +221,7 @@ hide_table_of_contents: false
- **Mock**: behavior + **assertions**; **stub**: **canned** responses; **spy**: **record** calls.
- If asked: Use a mock when the test must fail if a function wasn’t called.

53) Test Pyramid?
53) Test Pyramid(金字塔)?
- More **unit**, fewer **integration**, few **e2e** for **speed**/**stability**.
- If asked: UI tests are slow and flaky; keep them minimal but meaningful.

Expand Down