JavaScript only has one simple type, namely: |
var anumber = 137; // use var to define a number |
var astring = "1"; // or to define a string |
Loose typing in JavaScript allows interpreter to creatively interpret an expression. Note that strings take precedence over numbers: |
var x = astring + anumber; // results in x = "1137" |
(Early versions of JS inferred the type from the leftmost variable.) |
Use parseInt and parseFloat to extract numerical values from strings |
Note special value null (no quotes) can be used as a null value |
Strings can be delimited by '..text..' or "..text.." which are identical in meaning (unlike PERL). Also, one can use \n for newline and \t for tab (and a few others). |
Boolean literals are either true or false |
Comments come in two flavors: |
/* any text including newlines */ |
statements; // comment terminated by newline |