document.write("message");
- Generally avoid.
- Works okay when when run in-line as page is loading.
- If called after page is loaded (from a function, say), will replace
the entire document.
User Interaction
- Alert on load. (Booooo). [ Popups Source ]
- Alert on a button (as above).
- Popup window. [ Create Window Source ]
Basic Syntax.
- Similar to PHP, reflecting common ancestry.
- Same comments. // /* */
- Semicolons generally optional.
Expressions.
- Variables
- Can include $ as a letter.
- Case sensitive.
- Does not need $ to set off variables like PHP.
- Strings.
- Either " or '
- Equivalent, and may contain each other.
- No interpolation.
- No block quotes.
- Numerics
- Arrays: name = [ 'this', 'that', 'the other' ];
- Associative Arrays:
{ "cat" : "meow", "cow" : "moo", "bird" : "chirp" }
- Operators: usual suspects. +, -, *, /, %, ++, --, =, ==, !=, <, >, <=, >=, ===, !==, &&, ||, !
- Also += and the other update operators.
- String concat is + instead of ..
Dynamic typing.
Functions.
function fred(x,y,z)
{
return x*y+z;
}
Local v. global
- var declares a variable local to its function.
- Just use the name to create a variable global to the page.
if, while, switch: Familiar syntax.