Saved in this browser - sign in to keep your review list.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Keep going - a few more words and AI can grade it.
Interview lens
How interviewers actually use this question
Likely follow-ups
What's the difference between hiding a component with CSS and not rendering it at all?Not rendering unmounts it, so its state is lost and its effects clean up. CSS hiding keeps it mounted with its state, and it still renders.
If a ternary swaps <LoginForm /> for <SignupForm />, what happens to the state inside the form?A different type at the same spot means unmount and remount, so state resets. The same type keeps its state unless you change its key.
How would you render one of five views based on a status value without nesting ternaries?Use an object that maps each status to a component, or a switch with early returns. Mention a fallback for an unknown status.
React has no special template syntax for conditions, so I use plain JavaScript to decide what the component returns.
When I'm choosing between two things, I put a ternary in the JSX, like a welcome heading if the user is logged in and a login prompt if not.
When it's show or nothing, I use logical AND, so hasMessages && the message paragraph renders that paragraph or nothing at all.
For bigger branches, like admin versus logged-in user versus logged out, I use if and else with early returns before any JSX.
Watch the left side of &&, because if it's the number 0 and not a boolean, React renders a 0 on the page instead of nothing.
Weak answers to avoid
Only knows the ternaryThe interviewer wants to hear when each pattern fits. Use a ternary for two options, && for show or nothing, and early returns when there are several branches.
Misses the 0 trap with &&items.length && <List /> prints a stray 0 when the list is empty. Name the trap and the fix, which is a real boolean like items.length > 0.
Writes an if statement inside JSXJSX braces take expressions, not statements, so it won't compile. Move the if above the return, or use a ternary inline.
Nests ternaries several levels deepIt works, but it is hard to read and easy to break. Once there are more than two branches, use early returns or a lookup object.
Interview lens
Likely follow-ups, what you can say, and the weak answers to avoid.