Conditional - grungy wooden headline on Maple  - 3D rendered royalty free stock image. This image can be used for an online website banner ad or a print postcard.

Conditional Operator

JavaScript has a conditional operator that we can use in place of an if statement. Here is the syntax…

So we have a test , which is in the parentheses, then a question mark (?). If the test returns true, the expression prior to the colon returns. Otherwise, the content after the colon runs. These are used for simple if/else statements. Here is another example…

In this case, the expression will return the “yes” string because 5 is greater than 4.

Happy Coding!

Clay Hess

Share this post

Share on facebook
Share on google
Share on twitter
Share on linkedin
Share on pinterest
Share on print
Share on email
Skip to content