freeCodeCamp/curriculum/challenges/chinese/02-javascript-algorithms-an.../basic-javascript/comparison-with-the-strict-...

1.6 KiB
Raw Blame History

id title challengeType videoUrl forumTopicId dashedName
56533eb9ac21ba0edf2244d3 严格不等运算符 1 https://scrimba.com/c/cKekkUy 16791 comparison-with-the-strict-inequality-operator

--description--

严格不相等运算符(!==)与全等运算符是相反的。 这意味着严格不相等并返回 false 的地方,用严格相等运算符会返回 true反之亦然。 严格不相等运算符不会转换值的数据类型。

示例

3 !==  3  // false
3 !== '3' // true
4 !==  3  // true

--instructions--

if 语句中,添加严格不相等运算符,这样函数在当 val 不严格等于 17 的时候,会返回 Not Equal

--hints--

testStrictNotEqual(17) 应该返回字符串 Equal

assert(testStrictNotEqual(17) === 'Equal');

testStrictNotEqual("17") 应该返回字符串 Not Equal

assert(testStrictNotEqual('17') === 'Not Equal');

testStrictNotEqual(12) 应该返回字符串 Not Equal

assert(testStrictNotEqual(12) === 'Not Equal');

testStrictNotEqual("bob") 应该返回字符串 Not Equal

assert(testStrictNotEqual('bob') === 'Not Equal');

应该使用 !== 运算符

assert(code.match(/(val\s*!==\s*\d+)|(\d+\s*!==\s*val)/g).length > 0);

--seed--

--seed-contents--

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

testStrictNotEqual(10);

--solutions--

function testStrictNotEqual(val) {
  if (val !== 17) {
    return "Not Equal";
  }
  return "Equal";
}