homerboy homerboy - 1 year ago 154
CoffeeScript Question

If...then in JSX for Javascript

I've been writing Coffeescript/JSX and this is valid syntax:

<input type={if @state.name == "Test" then "checkbox"}/>

How do I do the same for plain Javascript? There is no
clause and I don't think I can do inline
checks like I can in Coffee?

Answer Source

Taking the answer from How to write an inline IF statement in JavaScript?

You can use the syntax 10 < 11 ? do this : do that where the ? is the then and the : is the else.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download