-> If the body of the response is truthy and the item field is truthy: assign item = response.body.item. If either of them is falsy assign item = 'default'.
NOTE: in JavaScript the && and || operators work differently than in other languages
left&&right===left// if left is falsyleft&&right===right// if left is truthyleft||right===right// if left is falsyleft||right===left// if left is truthy
Nice Article
Btw, you don't have to use the double not (
!!) operator in a condition. It is enough to just writebecause an
ifstatement checks thetruthyness (or thefalsyness) of the value.falsyvalues are:false0(zero)""(empty string)nullundefinedNaNEverything else will be treated as
truthy.The same rules apply to
Boolean(value)and!!value.This also works inside other boolean expressions so you can write for example:
->If the body of the response istruthyand the item field istruthy: assignitem = response.body.item. If either of them isfalsyassignitem = 'default'.Nice to know this! Thank you for sharing this it's very interesting Whaison