=== )是相等运算符( == )的对应物。但是,与尝试将两个值转换为常见类型的等式运算符不同,严格相等运算符不执行类型转换。如果要比较的值具有不同的类型,则认为它们不相等,并且严格相等运算符将返回false。 例子 3 === 3 //是的在第二个示例中,
3 ==='3'//假
3是Number类型, '3'是String类型。 if语句中使用strict equality运算符,因此当val严格等于7时,函数将返回“Equal” testStrict(10)应返回“Not Equal”
testString: 'assert(testStrict(10) === "Not Equal", "testStrict(10) should return "Not Equal"");'
- text: testStrict(7)应返回“Equal”
testString: 'assert(testStrict(7) === "Equal", "testStrict(7) should return "Equal"");'
- text: testStrict("7")应返回“Not Equal”
testString: 'assert(testStrict("7") === "Not Equal", "testStrict("7") should return "Not Equal"");'
- text: 您应该使用===运算符
testString: 'assert(code.match(/(val\s*===\s*\d+)|(\d+\s*===\s*val)/g).length > 0, "You should use the === operator");'
```