Can I assign a logical expression to a variable in JavaScript?

Viewed 48

I need to do multiple conditional checks, and instead of using a rather long if conditions, I'd like to store those multiple conditions in variables, then call them back later in the if statement.

var y = 1;
var checkY = y >=0 && y < 3;
if (checkY) {
console.log("that's good.");
}

Obviously it worked elsewhere, but in Udacity editor while submitting the solution it throws an error with "var y is undefined".

Is it just an issue with this specific site editor or there is something wrong with my code?

0 Answers
Related