JavaScript barebones
Posted August 30, 2008 at 6:34 pm in ProgrammingJavaScript has nothing to do with Java.
Comments use //.
Variable declaration with initialization syntax is
var variable_name = value/"string";
Variables follow normal programming scope. If they are created within the function, they are local only to that function and if they are created outside of a specific function, they are global variables.
Event handlers include:
- onabort() — Page loading aborted.
- onblur() — Object’s focus lost.
- onchange() — Object changed.
- onclick() — Object clicked.
- onerror() — Script encountered an error.
- onfocus() — Object has focus.
- onload() — Object finished loading.
- onmouseover() — Cursor placed over object.
- onmouseout() — Cursor moved off object.
- onselect() — Object’s content selected.
- onsubmit() — Form submitted.
- onunload() — Page has been left.
Function syntax:
function function_name() {statement(s);}
The prompt() function prompts the user for an input within a pop-up box.
The alert() function pops-up a box with an alert message.
To perform concatenation or use variables within strings, use +. Example:
document.write("Your name is " + name + "!");
Conditional syntax follows the same pattern as every other programming language.
if (condition) {statement(s);} else {statment(s);}
document.write(); writes to the DOM and document.window(); will point to a URI.
document.getElementById(“id”) will search the DOM for the id.
Commentary