Javascript Study Notes



Notes

command ends in semi-colon
case-sensitive
basic object of the web page is always the window
e.g. document.write - assumed window.document.write
// signifies javascript comment
four basic data types - variables: numbers, strings, boolean, and null
literals - variables with fixed values
creating variables: var xyz; xyz is now a variable
setting variable values: var xyz="this is the xyz variable"
to assign an initial value to a variable, use an assignment expression
four kinds of assignment expressions: assignment, arithmetic, string, logical
javascript counts starting at 0, except day of the month starts at 1
assignment operators: +, +=, -=
concantenation operator: +
within the script tag, any HTML tags use single quotes
equal sign for assignment: =
equal sign for comparison: ==
not: !
comparison operators: ==, !=, >, <, >=, <=
logical operators: &&, ||
arithmetic operators: +, -, *, /
string operators: +
conditional statements:
   if( ) { }
   if( ) { } else { }
index variable used to reference entry in an array - enclosed in square brackets
two main type of loops:
   while loop - continues until condition is met or fails to be met
   for and for in loops - iterate over a set range
for(initial value; condition; update expression) { }
update expression evaluated at end of javascript statements
break statement: breaks out of a loop
continue statement: jump to the next iterence of the javascript statements without completing the current pass
DOM - Document Object Module - determines how objects and subobjects, method and events are referenced in the code
Object - its properties are the attributes that are coded in HTML
function - groups together lines of script that perform a specific task into a single unit - usually scripted in the script part of the head section - defined by name and invoked by using its name followed by a set of parenthesis. can be passed parameters (arguments) and return results. arguments exist only for the life of the function. arguments can be objects, properties, variables, literals, arrays, or any combination. the order in which parameters are passed is the order in which they are defined in the function.
local variable - a variable declared within a function and available only within the function
global variable - a variable declared outside functions and available throughout the script.
return statement - functions return results through the return statement. can be a single value or "true" or "false".
defining an object - first must have its properties outlined. This is done by using a function that defines the name and properties of the object.
"this" - refers to the current object.
events - means by which interact with the browser window and the currently loaded document. Triggered in the browser primarily by user actions.
event handler - the triggers for events. part of HTML.


Objects

document
date


Methods

document.write()
getMonth()
getDate()
getDay()
getYear()
getFullYear()
getUTCFullYear()
getMilliseconds()
getSeconds()
getHours()
getMinutes()
getTimezoneOffset()
array()
alert()
prompt()


Special Characters

\n - new line \t - tab \r - carriage return \f - form feed \b - backspace \\ - output a backslash \" - output a double quote (instead of using an & character)


Statements

function function_name(parameters, arguments) {command block}


Events available in JavaScript

abort - occurs when the user cancels loading of an image
blur - Occurs when input focus is removed from a form element (when the user clicks outside a field) or focus is removed from a window
click - Occurs when the user clicks on a link or form element
change - Occurs when the value of a form field is changed by the user
error - Occurs when an error happens during loading of a document or image
focus - Occurs when input focus is given to a form element or a window
load - Occurs when a page is loaded into Navigator
mouseout - Occurs when the user moves the pointer off of a link or clickable area of an image map
mouseover - Occurs when the user moves the pointer over a hypertext link
reset - Occurs when the user clears a form using the Reset button
select - Occurs when the user selects a form element's field
submit - Occurs when a form is submitted (i.e., when the user clicks on a submit button)
unload - Occurs when the user leaves a page


Events Handlers

onAbort
onBlur
onClick
onChange
onError
onFocus
onLoad
onMouseout
onMouseover
onReset
onSelect
onSubmit
onUnload



Back to the Top

Back to LVS Home

To JavaScript Notes - Week One

To JavaScript Notes - Week Two

To JavaScript Notes - Week Three

To JavaScript Notes - Week Four

To JavaScript Notes - Week Five

To JavaScript Web Resources