Possible Duplicate:
Javascript : assign variable in if condition statement, good practice or not?
Is it bad practice to assign/evaluate things inside an if statement?
eg.
var foo;
var bar = function() { .. }
if(foo = bar()) {
..
}
Possible Duplicate:
Javascript : assign variable in if condition statement, good practice or not?
Is it bad practice to assign/evaluate things inside an if statement?
eg.
var foo;
var bar = function() { .. }
if(foo = bar()) {
..
}
Functionality-wise there's absolutely nothing wrong with that. But if you're going for readability, keep in mind that more junior members of your team (if any) may have a tougher time with less straight forward syntax as this.
This will work fine and is not bad practice in Javascript.
JSLint might not agree with me though ;-)