San*_*ing 0 javascript node.js ecmascript-6
谁能解释为什么下面不一样?
const j = 't1'
const t = 1
if (j === ['t'].concat(t)) {
console.log('the same')
}
Run Code Online (Sandbox Code Playgroud)
我原以为我会t1与比较t1,但我想我不是?
您正在使用Array.prototype.concat返回数组的方法。
['t'].concat(t); //["t", 1]
Run Code Online (Sandbox Code Playgroud)
这不等于值或类型 't1'
但是,如果您使用了String.prototype.concat,您将获得预期的结果。
't'.concat('1'); //"t1"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
55 次 |
| 最近记录: |