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

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -