Possible Duplicate:
Javascript === vs == : Does it matter which “equal” operator I use?
when i checked my code with JSLINT, it was full of errors…it works perfectly even in Ie6 but for some reason because i’m not an elegant coder i got more than 100 errors…
so i’d like to learn how to code better, error free… but when i used some suggestions JSLINT gave me like was to replace == with ===, well i did, and nothing was working…
so my question is: do we have to follow literally all the JSLINT suggestions?
JSLint tests a professional subset of Javascript, created by Douglas Crockford. Essentially, he seeks to carve only the “good parts” out of the JavaScript language, to make life for programmers easier and code more legible and predictable. So, the short answer is NO. You do not have to follow the instructions. Perfectly valid JavaScript code will, and does, fail JSLint all the time.
But the long answer is that your life will be significantly easier in the long run if you do.
Take === vs. ==, for example. The difference is testing for EQUALITY versus testing for IDENTITY. Or, as Crockford says in his book, JavaScript: The Good Parts:
So, if you’re using === instead of ==, your code will almost always perform as you expect it to, a small price to pay for typing an extra character. But if you use == and the operands are not of the same type — a string and an integer, for instance, JavaScript will first translate those values to the same type, and then compare them. And they might not do what you want or what you expected. And since, in JavaScript, you’re often dealing with elements brought in from the DOM, which come in as strings, you run into string conversion issues all the time.
As Crockford writes, here are some of the issues you could run into:
Screwy, eh? JavaScript: The Good Parts is a great book, super thin, and if you’ve been working with JavaScript for a while, it will change the way you code for the better. So will JSLint, if you bow your head like a good marine.
So. Long answer? No. You don’t have to do everything JSLint tells you. But you should.