【发布时间】:2021-04-13 00:36:24
【问题描述】:
let myName = 'vincenzo';
if (myName !== String) {
console.log('this is not a string');
} else if (myName.length % 2 === 0){
console.log(even);
} else if (myName.length % 2 !== 0){
console.log(odd);
}
谁能解释为什么这只返回“这不是一个字符串”?它不应该返回“偶数”吗?我不确定我哪里出错了
【问题讨论】:
-
提示:
typeof. -
提示:
typeof myName !== 'string' -
您应该避免在
else if中指定唯一的其他逻辑可能性。与if (x == 1)一样,else 是自动 的逻辑逆,例如if (x != 1)。不要指定明显的。
标签: javascript string variables logging operators