DEV Community

arfa
arfa

Posted on

Javascript conditional operator

Let's implement a simple function that takes two parameters " width" and " height" of a picture, and suppose to return true if our picture is a landscape and return false if it isn't.

we can handle it with this simple code

if(width > height) return true
return false
Enter fullscreen mode Exit fullscreen mode

but we can write it in a better way if we use a conditional operator

return width > height ? true : false
Enter fullscreen mode Exit fullscreen mode

we can improve it even further more like this

return width > height
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Build the product, not the plumbing—JavaScript first

Build the product, not the plumbing—JavaScript first

Kinde handles the boring but critical stuff: auth, permissions, and billing—all from one Javascript SDK.

Get a free account

👋 Kindness is contagious

If this **helped, please leave a ❤️ or a friendly comment!

Okay