Why does jshint not recognize an assignment as an expression?

user656925 picture user656925 · Nov 12, 2011 · Viewed 9k times · Source

How do I need to modify these lines to make jshint happy?

An assignment is an expression. Why doesn't jshint understand this? Obviously the interpreter does.

Line 572: while(bookmark_element=bookmark_list[iterator++])

Expected a conditional expression and instead saw an assignment.


Line 582: while(bookmark_element=bookmark_list[iterator++])

Expected a conditional expression and instead saw an assignment.


Line 623: while(element_iterator=element_iterator.nextSibling)

Expected a conditional expression and instead saw an assignment.

Answer

Rob W picture Rob W · Nov 12, 2011

If you really want to listen to JSHint, convert the expression to a boolean by:

while (!!(bookmark_element=bookmark_list[iterator++]))

! means: Something that evaluates to true is converted to false,
         something that evaluates to false is converted to true.

So, !! means: Convert something to the conditional representation.