FAQ: Advanced JSX - JSX Conditionals: If Statements That Do Work

This community-built FAQ covers the “JSX Conditionals: If Statements That Do Work” exercise from the lesson “Advanced JSX”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Web Development

Learn ReactJS: Part I

FAQs on the exercise JSX Conditionals: If Statements That Do Work

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

Should accept more answers that besides the if and else. Previous lessons teach us how to use ternary operator but does not accept it as an answer

Is there any harm in adding ( ) in single-line JSX code? I understand that it’s mandatory to wrap multiple lines of JSX elements in ( ) brackets, but I’m in the habit of always starting my JSX with them, as more often than not I’m writing more than one line of code. Is it just bad form?

For example, the compiler does not complain about the following:

// if/else statement begins here:
if (coinToss() === 'heads'){
  (
    img = <img src={pics.kitty} />
  )
}
else {
  img = <img src={pics.doggy} />
}

As you can see I’ve used the ( ) brackets for the first single line of JSX, but not the second in the else statement.