What is the difference between defaultProps and default parameter values?
Why Interviewers Ask This
Foundational questions like this help interviewers calibrate the rest of the interview. A confident, accurate answer signals that you have solid React.js basics — a prerequisite for any developer role.
Answer
Both provide fallback values for component props, but they work differently. defaultProps: a static property on the component class or function that React merges with the passed props before rendering. Deprecated for function components in React 18.3. MyComponent.defaultProps = { color: "blue", size: 16 };. Pros: works in class components; was the original React way. Cons: the defaults are defined separately from the component signature, making them less visible; deprecated for function components. Default parameter values: standard JavaScript destructuring defaults in the function signature. function Button({ color = "blue", size = 16, onClick }) { ... }. Pros: co-located with props; type inference works better in TypeScript; more idiomatic modern JavaScript; works for function components without any React-specific API. Cons: does not work in class components. Recommendation: always use JavaScript default parameter values for function components — they are cleaner, more visible, and better supported by tooling. Use defaultProps only if maintaining legacy class components.
Common Mistake
Don't just define the term — demonstrate that you understand when to use it and when not to. Showing awareness of trade-offs is what separates average from strong React.js candidates.
Previous
What is the reconciliation algorithm and Fiber?
Next
What is the difference between findDOMNode and ref?