Reputation: 51
The isCheck() function returns false if not radio buttons have been checked.
if (isCheck() === false) {
i = 0;
return i;
}
Upvotes: 2
Views: 3841
Reputation: 165
yes it works. alternatively you could use ternary operator using that syntax:
test ? expression1 : expression2
for example :
//init var i with some value
var i = 1;
function isCheck(){ return false;}
i = isCheck() === false ? 0 : i;
return i;
or simple:
//before you should initialize i
return !isCheck() ? 0 : i ;
Upvotes: 2
Reputation: 1868
Yes it is correct
You dont need to create a variable only to receive a bool and later do a validation you can do directly.
Upvotes: 0
Reputation: 50291
There is no wrong in executing a function inside if conditional statement.
For such case you can use ternary operator
var i=-1; // Note var key word & initialized with some value
isCheck() === false ? (i=0):(i=someOtherVal)
Upvotes: 1
Reputation:
I don't see why not, some will say its not conventional but it should work just fine!
Upvotes: 0