Lesson 11: IF stament


#1

I stuck at this lesson :
https://www.codecademy.com/courses/react-101/lessons/react-jsx-advanced/exercises/jsx-conditionals-ternary

I think “x?y:z” or in lesson 12: “x&&y”, i think it similar to IF stament in someway.
but in early lesson say “if stament do not work in JSX”,
but “The Ternary Operator” is OK?
can anyone explain for me.

sorry for my poor english.


#2

if statements and for loops are not expressions in JavaScript, so they can’t be used in JSX directly. Instead, you can put these in the surrounding code.

so we can’t use if and for inside a JSX directly (between the {}), however, a ternary operator is an expression so we can use it in JSX


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.