代码语言:javascript复制
const output = `${[] && 'Im'}possible!You should${'' && `n't`} see a therapist after so much JavaScript lol`
代码语言:javascript复制A: possible! You should see a therapist after so much JavaScript lol
B: Impossible! You should see a therapist after so much JavaScript lol
C: possible! You shouldn't see a therapist after so much JavaScript lol
D: Impossible! You shouldn't see a therapist after so much JavaScript lol
答案: B
[]
是一个真值。使用&&
运算符,如果左侧值是真值,则返回右侧值。在这种情况下,左侧值[]
是一个真值,所以返回Im
。
""
是一个假值。如果左侧值是假的,则不返回任何内容。 n't
不会被退回。