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

1.6 KiB

id title challengeType videoUrl forumTopicId dashedName
56533eb9ac21ba0edf2244d1 嚴格相等運算符 1 https://scrimba.com/c/cy87atr 16790 comparison-with-the-strict-equality-operator

--description--

嚴格相等運算符(===)是相對相等操作符(==)的另一種比較操作符。 與相等操作符轉換數據兩類型不同,嚴格相等運算符不會做類型轉換。

如果比較的值類型不同,那麼在嚴格相等運算符比較下它們是不相等的,會返回 false 。

示例

3 ===  3
3 === '3'

這些條件將分別返回 true and false

在第二個例子中,3 是一個 Number 類型,而 '3' 是一個 String 類型。

--instructions--

if 語句中,添加不相等運算符,這樣函數在當 val 嚴格等於 7 的時候,會返回 Equal

--hints--

testStrict(10) 應該返回字符串 Not Equal

assert(testStrict(10) === 'Not Equal');

testStrict(7) 應該返回字符串 Equal

assert(testStrict(7) === 'Equal');

testStrict("7") 應該返回字符串 Not Equal

assert(testStrict('7') === 'Not Equal');

你應該使用 === 運算符。

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

--seed--

--seed-contents--

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

testStrict(10);

--solutions--

function testStrict(val) {
  if (val === 7) {
    return "Equal";
  }
  return "Not Equal";
}