admin管理员组文章数量:1287126
I've created a simple if/else statement like so :
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 my first course".substring(0,26));
}
Unfortunately, the console returns this error : SyntaxError: Unexpected identifier
I've tried to add square brackets to var myName = "Mark"; but it didn't help.
I've created a simple if/else statement like so :
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 my first course".substring(0,26));
}
Unfortunately, the console returns this error : SyntaxError: Unexpected identifier
I've tried to add square brackets to var myName = "Mark"; but it didn't help.
Share Improve this question edited Nov 16, 2014 at 1:36 user3717023 asked Sep 24, 2013 at 18:58 Danny_StudentDanny_Student 1531 gold badge3 silver badges11 bronze badges 01 Answer
Reset to default 5With
var myName = ["Mark"]
you are assiging an array to the myName
, which is not what you want in this case:
var myName = "Mark"
You have to use parentheses around the if-condition. Also the semicolon is wrong:
if (myName.length <= 3){
...
}
In the else-block you've got the first statement wrong. You have to use + to concatenate the arguments that you want to print:
console.log("Variable consists of" + myName.length);
本文标签:
版权声明:本文标题:syntax - The cause of SyntaxError: Unexpected identifier in a JavaScript conditional statement based on the length of a string - 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741307690a2371468.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论