选择篇(107)-下面代码的输出是什么?

2022-12-05 13:56:45 浏览数 (1)

代码语言: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不会被退回。

im

0 人点赞