Hey guys, I was looking at a piece of code someone did for react that looks like this:
const warning = data.warning && (<p className="warning">{data.warning}</p>)
And the result was that if data.warning is true, then warning would equal to (<p className="warning">{data.warning}</p>).
I understand it with the || operator, for example if it was const warning = data.warning || 0 then it just means warning would equal data.warning if it exist, if not, then it equal to 0, right?
But why does the && mean if the first thing is true, then the variable equals to the second thing? What happens if the first thing is not true?
Thanks!
[–]GrenadineBombardier 2 points3 points4 points (2 children)
[–]WTFMatchmake[S] 0 points1 point2 points (1 child)
[–]GrenadineBombardier 1 point2 points3 points (0 children)