1 | JavaScript only has one simple type, namely: |
2 | var anumber = 137; // use var to define a number |
3 | var astring = "1"; // or to define a string |
4 | Loose typing in JavaScript allows interpreter to creatively interpret an expression. Note that strings take precedence over numbers: |
5 | var x = astring + anumber; // results in x = "1137" |
6 | (Early versions of JS inferred the type from the leftmost variable.) |
7 | Use parseInt and parseFloat to extract numerical values from strings |
8 | Note special value null (no quotes) can be used as a null value |
9 | 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). |
10 | Boolean literals are either true or false |
11 | Comments come in two flavors: |
12 | /* any text including newlines */ |
13 | statements; // comment terminated by newline |