I’m getting an odd code syntax warning in Visual Studio, for a bit of JavaScript:
If(1==1) { alert("!"); }
The warning is on the opening curly brace:
TS1005 (JS) ‘;’ expected.
I tried adding a semicolon after the closing curly brace, but that didn’t make a difference:
I’ve also determined that when this if
block is included anywhere in the script—with or without the trailing semicolon—the entire script fails to execute in the browser (Chrome, latest version).
According to W3Schools, the syntax is correct.
This seems very strange. What’s going wrong here?
Advertisement
Answer
If
should not have a capital letter. If
is recognized as a function by VS and therefore expects a ;
. The warning should be fixed by using if
instead of If
. I tested it locally on my VS IDE and using If
generated the same warning, but if
is fine.