declaring a variable within conditional expressions (ternary operator)
Is it possible to declare the variable within a conditional expression?
for example: The code below return a syntax error (because I've declared
the variable x within the conditional expression?).
var a = document.getElementById("userData");
var d = a.value;
function() {
(d.length>15)?(
alert("your input was too long")):(
var x = parseInt(d).toString(2),
a.value=x
);
}
obviously this can be fixed by simply adding var x; outside the statement,
but is it possible for variables to be declared here?
No comments:
Post a Comment