Beatdigital

Websites made easy...

  • Increase font size
  • Default font size
  • Decrease font size
Home Articles Simple Javascript Syntax Quick-Reference

Simple Javascript Syntax Quick-Reference

E-mail Print PDF

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:
var myHeredoc = (<r><![CDATA[
An unaltered
multiline string!
]]></r>).toString();

alert(myHeredoc);

Comments

Name *
Email (For verification & Replies)
URL
ChronoComments by Joomla Professional Solutions
Submit Comment