I don’t understand what these code is doing.
And syntax of Part 3 is really complicated.
Could some explain it for me && give me some tutorial to read? Thanks a million!
Yes you’re right. I knew what I meant at the time, but was tired. My apologies for any confusion, I’ve removed the previous post.
The updated part I’ve bolded below:
With || operators JavaScript keeps on evaluating from left to right, until a truthy value occurs, giving that truthy value or failing that, the last falsey value.
With && operators JavaScript keeps on evaluating from left to right, until a falsey value occurs, giving that falsey value or failing that, the last true value.
If a evaluates to true, then that evaluation is the value of a.
Why does that matter? Because String(a) could be “Cucumber” when a is “Cucumber”, or it could be “[object Object]” when a is an object.
Or, it could be an empty string “” when a is an array.
Confusingly, ( && “something else”) evaluates to true, even though String() evaluates to an empty string, which evaluates to false.
It’s probably fairly important to point out that truthy values can be a bit misleading.
0 is false
“” is false
is true. So is {}. null,NaN,false, and undefined (which is usually what the || is used for in this case) are false.
So be wary of using || for evaluating things that might legitimately return 0, for example.
The first one is an expression interpolation in a template literal; the second one is an expression embedded in JSX, preceded by the literal character "@".
It’s a bit confusing as decorators do look similar, but the @ would be followed by the name of the decorator function then – you have to look at code in the pen to see that it’s not part of the expression here.