在JavaScript中,0、空字符串和'0'的真假值分别是:0为false,空字符串为false,'0'为true。
0的真假值
0在JavaScript中是一个数字,它是一个表示“没有数字”的特殊值,它的真假值为false。
空字符串的真假值
空字符串是指字符串中没有任何字符的字符串,在JavaScript中,它的真假值也为false。
'0'的真假值
'0'是指一个字符串,其中包含一个字符“0”,它是一个非空字符串,它的真假值为true。
if (0) { console.log('0 is true'); } else { console.log('0 is false'); } if ('') { console.log('empty string is true'); } else { console.log('empty string is false'); } if ('0') { console.log('string 0 is true'); } else { console.log('string 0 is false'); }
0、空字符串和'0'在JavaScript中的真假值分别为:0为false,空字符串为false,'0'为true。