triple-equals

Can I use triple equals for JavaScript string comparison?

浪尽此生 提交于 2021-02-18 20:54:05
问题 This is an extremely basic question, I know, but I couldn't understand what's going on from Google and Stack Overflow. I looked here and here to learn how to compare strings in JavaScript. Neither mentioned triple equals ( === ) in their answers, and said that it's better to use your own function ( str1 < str2 ? -1 : str1 > str2 ). However, going through explanations about === in Stack Overflow (here and here), the answers contain string comparisons. From what I saw in those answers, === does

JavaScript triple equals and three-variable comparison

佐手、 提交于 2019-11-28 08:24:45
问题 Can somebody explain this? 1 == 1 //true, as expected 1 === 1 //true, as expected 1 == 1 == 1 //true, as expected 1 == 1 == 2 //false, as expected 1 === 1 === 2 //false, as expected 1 === 1 === 1 //false? <-- Also is there a name for boolean logic that compares more than two numbers in this way (I called it "three-variable comparison" but I think that'd be wrong...) 回答1: This expression: 1 === 1 === 1 Is evaluated as: (1 === 1) === 1 After evaluating the expression inside parentheses: true ==