JSLint Expected '===' and instead saw '=='

前端 未结 8 1844
我在风中等你
我在风中等你 2020-11-30 21:08

Recently I was running some of my code through JSLint when I came up with this error. The thing I think is funny about this error though is that it automatically assumes tha

相关标签:
8条回答
  • 2020-11-30 21:48

    Triple-equal is different to double-equal because in addition to checking whether the two sides are the same value, triple-equal also checks that they are the same data type.

    So ("4" == 4) is true, whereas ("4" === 4) is false.

    Triple-equal also runs slightly quicker, because JavaScript doesn't have to waste time doing any type conversions prior to giving you the answer.

    JSLint is deliberately aimed at making your JavaScript code as strict as possible, with the aim of reducing obscure bugs. It highlights this sort of thing to try to get you to code in a way that forces you to respect data types.

    But the good thing about JSLint is that it is just a guide. As they say on the site, it will hurt your feelings, even if you're a very good JavaScript programmer. But you shouldn't feel obliged to follow its advice. If you've read what it has to say and you understand it, but you are sure your code isn't going to break, then there's no compulsion on you to change anything.

    You can even tell JSLint to ignore categories of checks if you don't want to be bombarded with warnings that you're not going to do anything about.

    0 讨论(0)
  • 2020-11-30 21:53

    Well it can't really cause problems, it's just giving you advice. Take it or leave it. That said, I'm not sure how clever it is. There may well be contexts in which it doesn't present it as an issue.

    0 讨论(0)
提交回复
热议问题