开发者

Javascript dual If statements

开发者 https://www.devze.com 2023-02-12 21:41 出处:网络
With the fo开发者_运维技巧llowing code I am trying to set both the test title and object. The code works if I use one line but not both.

With the fo开发者_运维技巧llowing code I am trying to set both the test title and object. The code works if I use one line but not both.

if (today <= test0) var testTitle = testTitle0
if (today <= test0) var testObject = testObject0

Outcome:

if (today <= test0) var testTitle = testTitle0 & var testObject = testObject0


You are missing curly braces and semicolons:

if (today <= test0) {
    var testTitle = testTitle0,
        testObject = testObject0;
}


if (today <= test0) 
{
    var testTitle = testTitle0;
    var testObject = testObject0;
}

Learn to use braces around if statements and semicolons at the end of your lines.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号