2.0 KiB
Raw Blame History

id, title, challengeType, videoUrl, localeTitle
id title challengeType videoUrl localeTitle
56533eb9ac21ba0edf2244d1 Comparison with the Strict Equality Operator 1 与严格平等算子的比较

Description

严格相等( === )是相等运算符( == 的对应物。但是与尝试将两个值转换为常见类型的等式运算符不同严格相等运算符不执行类型转换。如果要比较的值具有不同的类型则认为它们不相等并且严格相等运算符将返回false。 例子
3 === 3 //是的
3 ==='3'//假
在第二个示例中, 3Number类型, '3'String类型。

Instructions

if语句中使用strict equality运算符因此当val严格等于7函数将返回“Equal”

Tests

tests:
  - text: <code>testStrict(10)</code>应返回“Not Equal”
    testString: 'assert(testStrict(10) === "Not Equal", "<code>testStrict(10)</code> should return "Not Equal"");'
  - text: <code>testStrict(7)</code>应返回“Equal”
    testString: 'assert(testStrict(7) === "Equal", "<code>testStrict(7)</code> should return "Equal"");'
  - text: <code>testStrict(&quot;7&quot;)</code>应返回“Not Equal”
    testString: 'assert(testStrict("7") === "Not Equal", "<code>testStrict("7")</code> should return "Not Equal"");'
  - text: 您应该使用<code>===</code>运算符
    testString: 'assert(code.match(/(val\s*===\s*\d+)|(\d+\s*===\s*val)/g).length > 0, "You should use the <code>===</code> operator");'

Challenge Seed

// Setup
function testStrict(val) {
  if (val) { // Change this line
    return "Equal";
  }
  return "Not Equal";
}

// Change this value to test
testStrict(10);

Solution

// solution required