Rule Details

Options

"except-parens" (default) allows assignments in test conditions only if they are enclosed in parentheses (for example, to allow reassigning a variable in the test of a while or do...while loop)

"always" disallows all assignments in test conditions

except-parens

Examples of incorrect code for this rule with the default "except-parens" option:

/*eslint no-cond-assign: "error"*/// Unintentional assignmentvarx;if(x=0){varb=1;}// Practical example that is similar to an errorfunctionsetHeight(someNode){"use strict";do{someNode.height="100px";}while(someNode=someNode.parentNode);}

Examples of correct code for this rule with the default "except-parens" option:

always

Examples of incorrect code for this rule with the "always" option:

/*eslint no-cond-assign: ["error", "always"]*/// Unintentional assignmentvarx;if(x=0){varb=1;}// Practical example that is similar to an errorfunctionsetHeight(someNode){"use strict";do{someNode.height="100px";}while(someNode=someNode.parentNode);}// Practical example that wraps the assignment in parenthesesfunctionsetHeight(someNode){"use strict";do{someNode.height="100px";}while((someNode=someNode.parentNode));}// Practical example that wraps the assignment and tests for 'null'functionsetHeight(someNode){"use strict";do{someNode.height="100px";}while((someNode=someNode.parentNode)!==null);}