JavaScript barebones

Posted August 30, 2008 at 6:34 pm in Programming

JavaScript 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:

  1. onabort() — Page loading aborted.
  2. onblur() — Object’s focus lost.
  3. onchange() — Object changed.
  4. onclick() — Object clicked.
  5. onerror() — Script encountered an error.
  6. onfocus() — Object has focus.
  7. onload() — Object finished loading.
  8. onmouseover() — Cursor placed over object.
  9. onmouseout() — Cursor moved off object.
  10. onselect() — Object’s content selected.
  11. onsubmit() — Form submitted.
  12. 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

+

Add Your Comment

Your email address will never be shared or published.

Your Name:

Your Email:

Your Site: