jquery - ReferenceError: Invalid left-hand side in assignment using OR -
data['username'] = $("#username").val() || validated = false; if(validated){ //save db } i want write shorter code, assign validated false if username empty. why doesn't work above code?
|| binds stronger = (see https://developer.mozilla.org/de/docs/web/javascript/reference/operators/operator_precedence)
so need put parentheses around (valided = false).
otherwise first evaluates e.g. ('' || undefined) , attempts assign false expression.
Comments
Post a Comment