I Computer a Life-long Learner

Javascript 中(==)与(===)区别

2018-02-04

Javascript 中(==)与(===)区别

Javascript 中(==)与(===)区别

通过代码来说明是更容易的

if(3 == "3"){
    console.log("They are the same");
} else {
    console.log("They are not the same.");
}

OUTPUT:

They are the same

第 2 个示例:

if(3 === "3"){
    console.log("They are the same");
} else {
    console.log("They are not the same.");
}

OUTPUT:

They are not the same.

总结

== 在比较前会进行类型的转换,而 === 则会对类型与值都进行比较。


Comments(需要科学上网)