Before class syntax, constructor functions and prototypes were the main way to share behavior, and that model still exists underneath modern classes.
- Functions can act as constructors
- Shared methods usually live on the prototype
- Property lookup follows the prototype chain
JavaScript's `Date` object represents points in time and exposes local or UTC getters, setters, and formatting helpers.
- Dates are stored as timestamps
- Timezone handling can surprise people
- Common methods expose year, month, day, and time parts
The DOM is the browser's tree representation of the page, and JavaScript can select, traverse, and update nodes through several APIs.
- Selectors return elements or node lists
- DOM manipulation changes the page tree
- `textContent` is safer than arbitrary `innerHTML`
Loose equality performs coercion, strict equality compares without coercion, and objects are equal only when they reference the same object.
- Prefer `===` and `!==`
- `==` follows coercion rules
- Object equality is reference-based
JavaScript handles recoverable runtime failures with exceptions, and you can throw your own error objects when needed.
- `finally` runs regardless of success or failure
- Throw meaningful error types
- Custom errors improve clarity
JavaScript's event loop decides when queued async work can return to the call stack, with microtasks running before the next macrotask.
- The stack must be empty before queued work runs
- Promise callbacks go to the microtask queue
- `setTimeout` is a minimum delay, not an exact execution time
Browser events travel through capture and bubble phases, and good event handling often relies on delegation and controlled propagation.
- `addEventListener` can listen in capture or bubble phase
- Delegation reduces many per-node listeners
- `preventDefault` and `stopPropagation` solve different problems
JavaScript creates execution contexts for code execution, uses a call stack for active functions, resolves variables through the scope chain, and stores objects in memory.
- Contexts track variables and `this`
- The call stack orders active frames
- Heap memory holds reference values
JavaScript functions are first-class values, which is why callbacks, higher-order utilities, and different function forms all matter.
- Declarations and expressions behave differently
- Arrow functions change `this` behavior
- Pure functions avoid hidden side effects
JavaScript supports functional patterns through immutable updates, transformation helpers, and composing small functions into larger pipelines.
- Immutability reduces accidental shared-state bugs
- `map`, `filter`, and `reduce` support declarative transforms
- Composition connects small reusable functions
JavaScript uses garbage collection, but leaks still happen when references stay alive unexpectedly or when code creates unnecessary work.
- Leaked references block collection
- Shallow copies can share nested state
- Repeated DOM writes and bad loops can hurt performance
JavaScript can convert values automatically or explicitly, and interview questions often focus on where that behavior becomes surprising.
- Explicit conversion is easier to reason about
- `parseInt` and `Number` do different jobs
- Coercion can hide bugs