JavaScript Ternary Operator in Less Than One Minute

Опубликовано: 13 Декабрь 2024
на канале: Ado Kukic
3,572
170

The JavaScript Ternary Operator allows you to shorthand if/else statement and one-line the operations.

The ternary operator format is as follows:

{condition to evaluate} ? {code to execute if condition is true} : {code to execute if condition is false};

You can one line your entire operation like so:

isWeekend ? console.log("Party Time!") : console.log("Work time");

Or separate it on multiple lines like in the short above.

Happy coding :)