← Bitkernel Interview Insights
My first instinct was just to use `alert(message)` and then set `window.location.href = targetUrl` right after.
Start by clarifying the requirements and edge cases, then outline a simple implementation using window.alert for the popup and window.location.href for the redirect. Emphasize the guard condition to ensure redirect only occurs for a non-empty string targetUrl.
Pro tip: Mention that while alert is synchronous and simple, in a real app you might prefer a custom modal for better UX and testability; but for this constraint, alert is appropriate. Also, note that you should avoid using window.open for redirect as it may be blocked by popup blockers.
Confirm that the popup should be a blocking alert, and that redirect should only happen if targetUrl is a non-empty string. Ask about handling edge cases like null, undefined, or whitespace-only strings.
Define the function to accept message and targetUrl. Inside, show the popup with the message, then check if targetUrl is a non-empty string before redirecting.
Use window.alert(message) to display the popup. After alert returns (user closes it), check typeof targetUrl === 'string' && targetUrl.trim() !== '' and then set window.location.href = targetUrl.
Handle cases where targetUrl is not a string, is empty, or contains only whitespace. Optionally, validate that targetUrl is a safe URL to prevent open redirect vulnerabilities.
Mention testing with various inputs. Discuss trade-offs: alert is synchronous and simple but blocks the UI and is not customizable; a custom modal would be asynchronous and require a callback or promise.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.