syntax - The cause of SyntaxError: Unexpected identifier in a JavaScript conditional statement based on the length of a string -
i've created simple if/else statement :
var myname = ["mark"]; if myname.length <= 3; { console.log("it's not true"); } else { console.log("variable consists of" myname.length); console.log("i finished first course".substring(0,26)); }
unfortunately, console returns error : syntaxerror: unexpected identifier
i've tried add square brackets var myname = "mark"; didn't help.
with
var myname = ["mark"]
you assiging array myname
, not want in case:
var myname = "mark"
you have use parentheses around if-condition. semicolon wrong:
if (myname.length <= 3){ ... }
in else-block you've got first statement wrong. have use + concatenate arguments want print:
console.log("variable consists of" + myname.length);
Comments
Post a Comment