With this message, JSLint is reporting that is has encountered one expression when it expected to see another.
One common cause of this message is when JSLint encounters the equality operator ( ‘==’), and reports that it expects an identity operator (‘===’):
Expected ‘===’ and instead saw ‘==’.
In most cases these operators will operate in the same manner, however there are occasions where their behaviour will differ:
alert (1=="1"); //alerts 'true'; alert (1==="1"); //alerts 'false';
See it work at this JSFiddle.
Here the identity operator is checking that the two items for comparison are of the same type. There are, of course, two counterpart operators, the inequality operator (‘!=’), and the non-identity operator (‘!===’). These will have the same relative behaviour.
JSLint expects you to use the identity operators in place of their equality counterpart at all times.
Refer to this article on JavaScript operators for more information on:
- arithmatic operators,
- relational operators,
- string operators,
- logical operators,
- bitwise operators, and
- a few others that don’t really fit into any category.
A Guide To JSLint Messages
This article is one of a series on the error and warning messages produced by JSLint.
[...] zeros ‘{a}’. Each value should have its own case label. Empty Block eval is evil. Expected ‘{a}’ and instead saw ‘{b}’. Expected ‘{a}’ to have an indentation of {b} instead of {c}. Expected ‘{a}’ [...]
[...] could be argued that this is one of the family of messages under Expected ‘{a}’ and instead saw ‘{b}’. One of my university professor referred to as ‘error 1′, because it was the single [...]