Simple Javascript Syntax Quick-Reference
Shorthand Conditional (If, Then Statement):
condition ? true : false
ex:
window.location == "http://google.com" ?
alert("you are at google.com!")
: alert("you are not at google.com :(");
Multiple Variable Declaration:
var variable1, variable2, variableN;
ex:
var myCat, myDog, myRat;
Unassigning (Deleting) a Variable:
variable = this.undefined;
ex:
myVar = this.undefined;
if (myVar) alert("myVar is still defined!");
Variable Assignment Across Multiple Lines:
var name = "text \
more text \
end of text";
ex:
var myString = "my string \
more string \
more string";
alert(myString);
Another Multi-line String (Heredoc):
var variable = (<r><![CDATA[
content
]]></r>).toString();
ex:
ex:
var myHeredoc = (<r><![CDATA[
An unaltered
multiline string!
]]></r>).toString();
alert(myHeredoc);