Expand ternary assignments, declarations and returns into readable if/else blocks, safely skipping ?? and ?. operators. Ternary to If/Else is a free online tool from the ToolsRift JavaScript Tools collection. It runs entirely in your browser — nothing to install, no signup, and your data never leaves your device.
Paste statements that use the ? : ternary operator, one per line, then click Convert to expand each recognised statement into an if/else block.
Three forms per line: a declaration (const/let/var x = c ? a : b), a plain assignment (x = c ? a : b) and a return (return c ? a : b). Other lines are left unchanged.
No. The nullish coalescing operator ?? and optional chaining ?. are detected and skipped so they are never mistaken for a ternary.
The outer ternary is expanded and any nested ternary is kept intact inside the branch, so the code stays valid — run it again to expand deeper levels.