Ternary Operator (JavaScript)

The ternary operator is a one-line shortcut for an if/else that returns a value. It uses the form condition ? valueIfTrue : valueIfFalse.

Welcome to LearnCodingFast — free, interactive programming lessons covering Python, JavaScript, Java, C++, C#, SQL, HTML/CSS, React, AI and more. Every course is hands-on with examples you can run in your browser.

Loading interactive version…