Machine Coding Round: Edge Cases to Handle
Handling edge cases shows attention to detail. Here are the edge cases to always check.
Machine Coding Round: Edge Cases to Handle
Handling edge cases shows attention to detail and scores higher. Here are the edge cases to always check.
General Edge Cases
- Empty input: what happens when the user has not typed anything?
- No results: what happens when there are no matches?
- Very long input: does the UI handle long strings gracefully?
- Special characters: does it handle
, !, @, #, $correctly? - Rapid input: does it handle fast typing (debounce)?
- Empty state: what does the user see when there is nothing?
- Loading state: what does the user see while waiting?
- Error state: what does the user see when something fails?
Component-Specific Edge Cases
Autocomplete Search Bar
- Empty input (show all or show nothing?).
- No results (show "no results found").
- Case sensitivity (should "Apple" match "apple"?).
- Very long query.
- Special characters.
- Rapid typing (debounce).
- Keyboard navigation (arrow up/down, enter, escape).
- Click outside to close.
Pagination
- Only one page (hide pagination?).
- Current page is the first or last.
- Very many pages (show ellipsis).
- Empty data.
- Page size changes.
OTP Input
- Pasting a full OTP.
- Backspace to go to the previous input.
- Only numeric input.
- Auto-focus to the next input.
- Submit when all inputs are filled.
Food Ordering App
- Empty cart.
- Quantity 0 (should not be possible).
- Search with no results.
- Filters with no results.
- Total price calculation with decimals.
Modal/Dialog
- Click outside to close.
- Escape key to close.
- Focus trap (tab should stay inside the modal).
- Scroll lock on the body.
How to Handle Edge Cases
- List them before coding: write down edge cases during the planning phase.
- Handle them after core: build the core first, then add edge case handling.
- Test them: manually test each edge case.
- Show appropriate UI: empty state, loading state, error state.
Empty State Pattern
if (results.length === 0) { renderEmptyState("No results found"); return; } renderResults(results);
The Takeaway
Always handle edge cases: empty input, no results, long input, special characters, rapid input, empty/loading/error states. List them before coding, handle them after the core, and test each one. Edge case handling shows attention to detail and scores higher.
Empty input, no results, very long input, special characters, rapid typing (debounce), empty state, loading state, and error state. Also component-specific cases like keyboard navigation, pasting, and click outside.
List them before coding (during planning), handle them after building the core, test each one manually, and show appropriate UI (empty state, loading state, error state). Do not let the app break or show nothing.
Empty input, no results, case sensitivity, very long query, special characters, rapid typing (debounce), keyboard navigation (arrow up/down, enter, escape), and click outside to close.
Only one page (hide pagination?), current page is first or last, very many pages (show ellipsis), empty data, and page size changes.
It shows attention to detail and production-readiness. A component that works for the happy path but breaks on edge cases is not production-quality. Handling edge cases scores higher than ignoring them.
Ready to master React completely?
Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course to dive deeper with high-quality video tutorials, solve interview questions, and a premium community.
Master React
Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course.

