jamesallardice / jslint-error-explanations

:memo: Explanations of all the (sometimes cryptic) error messages thrown by JSLint and JSHint
http://linterrors.com
293 stars 35 forks source link

Explain JSLint "Unexpected assignment expression." #8

Closed XP1 closed 10 years ago

XP1 commented 11 years ago

Explain JSLint "Unexpected assignment expression."

Tolerate assignment expressions: true if assignment should be allowed outside of statement position

ass: true, if assignment expressions should be allowed

https://github.com/douglascrockford/JSLint/commit/abc0d34007353642b8a4a822627549c459070f8b

Example:

(function (console, window, HTMLElement) {
    "use strict";

    var children = [];

    var document = window.document;
    var element = document.body;
    while ((element = element.firstElementChild) instanceof HTMLElement) {
        children.push(element);
    }

    console.log(children);
}(this.console, this, this.HTMLElement));
XP1 commented 11 years ago

JSLint discussion on Google+: https://plus.google.com/118095276221607585885/posts/WZwU74SvTZd

On May 2, 2013, Douglas Crockford said:

There is a new option, Tolerate assignment operators. Normally, assignment is allowed only in statement position. This option allows assignment in expression position. Use of this option is not recommended.

jamesallardice commented 11 years ago

Thanks, I'll get an article for this up as soon as I can. If you have enough information to write one yourself, please feel free to do so and open a pull request.

jamesallardice commented 10 years ago

http://jslinterrors.com/unexpected-assignment-expression