Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Take Control of Errors with componentDidCatch()

Santiago Herrera
Santiago Herrera
9,547 Points

Why Does Guil use if else statements instead of : and ? more over in a React v16 video?

Title

1 Answer

Steven Parker
Steven Parker
231,269 Points

I haven't seen the video, but I can tell you that the ternary operator ("? :") is intended to be evaluated as an expression and return a value, and not used to control statement execution.

On the other hand, the "if" (and "else") statements are specifically for conditional statement execution.

So the choice should be based on what is needed in the program.