Last Modified: 09/19/08 - (under construction)
Item | Description |
Resources | Resources
|
Organizations | Organizations
|
<script> Tag: JavaScript vs JScript vs VBScript |
JavaScript vs JScript
Example of a simple JavaScript function. <head> |
Browser Environment Info | Browser Environment Info
|
Variables: Visibility | Visibility
|
Variables: Naming Conventions | Variable Naming Conventions This is my suggestion. I follow this same type of "Variable Naming Convention" for other languages.
|
functions | functions
|
Function | Description |
Script Tags | |
Comments | Comments
|
var | var <variable name> Returns: Nothing Declares a variable. Examples: var blnDebug = true, strDebugMsg = "", <more statements ...>; var strHml = ""; Var info - see the section called: "Variables: Visibility" |
Control Structure: if() |
Control Structure: if()
|
Control Structure: Looping |
Control Structure:
Looping Control Structure: Examples
Control Structure: Looping - for
Control Structure: Looping - miscellaneous statements
|
with | |
function & return | |
new | |
this | |
Item | Information |
Create an Object & List it's properties | Example:
JavaScript Objects - Create & List Properties
function fObjectCreateAndList() { |
Global Objects - you can't loop through the values. | With Global Object, to my knowledge you
can't loop through the properties. Ex: Math, Date |
Item | Description |
setTimeout() | |
typeof | Determine the type of Variable or if
it doesn't exists ("undefined"). Note: This is vary handy when you needed it !!! Examples
|
void("") or void(0) | Not sure what this does, but here is
how I use it. Example #1: void('') - (note: 2 single quotes - not 1 double quote). This example allows me to run a JavaScript function and not change the web screen. <script language="JavaScript"> function fMyFunction(strMsg) { alert(strMsg) } </script> <a href="javascript:fMyFunction("Hello World");void('')">Development Testing</a> |
eval() | Evaluates an expression. This is
a way to dynamically create JavaScript and then run it. You
can dynamically create a name of an object in a text string and the
eval() the string to return the value. |
escape() | escape(<string> [,1]) Returns: String (encoded) Returns an "escaped string" (URL encoded). (Note: spaces are converted to %20 etc....). Used to encode a string for the URL line. Example: Optional parm value of 1 = Encode the "+" sign also. |
isNaN() | Evaluates and argument to determine if
it's "Not a Number" |
Number() | Converts parm to a number Example: |
parseFloat() | Converts a string to a float. Warning: parseInt('09') = 0 |
parseInt() | Converts a string to an integer. var intTest = parseInt( <string> ); Warning:
|
String() | |
unescape() | unescape(<encoded
string>) Returns: String Returns a string value of an "escaped string". (Note: %20 converted to space, etc....) Example: var strUnEncoded = unescape("Hello%20World") Returns: "Hello World" see: escape() |
unwatch() | Used with some browsers for debugging code. |
watch() | Used with some browsers for debugging code. |
Item | Description |
General Info | Creating a String: strExample = "Hello World" strExample = 'Hello World' strExample = new String("Hello World") Joining Strings: |
Relevant functions: split() parseInt() parseFloat() |
split() - see "Array Functions"
section. parseInt() - see General & Global functions. |
<string>.indexOf() | intReturn = <string object>.indexOf(<string
to find>,intStartingPosition) 0 = 1st Char Examples: |
String() | String( <object or value> ) Returns: String Returns a string representation of the parm. Same as <object>.toString() Example: String( <array object> ) - returns a comma-delimited string of the contents. |
<string>.replace() |
Replace a char with a char. strSource = "Hello"; Example:
replace() |
<string>.search | Search for a regular expression
within a string. Return: -1 = not found, 0=first position. JavaScript Search & RegExp - Examples and reference info.
|
<string>.substring |
Returns a substring of a string based
on a Start & Stop index value. (Note: first position is 0) <string>.substring(StartIndex, StopIndex) |
<string>.substr |
Returns a substring of a string based
on a Start index value and then a length of characters. (Note: first
position is 0) <string>.substr(start [, length ]) |
<string>.toLowerCase() |
Returns the lower case value of the
string.
|
<string>.toUpperCase() | Returns the upper case value of the
string. ex: "Hello World".toUpperCase() |
Work around: right() function |
To my knowledge there is no right()
function. Here is a work around. var strTest = "0005" intLen=2; strTest = strTest.substr(strTest.length>=intLen?strTest.length-intLen:0, intLen) Note: strTest now equals: "05" |
Item | Description |
Relevant functions described in other sections | Global Functions (see the other
section)
|
Examples |
|
abs | Math.abs( var ) - Absolute value.
(Returns the positive number.) Ex: Math.abs( 1 ) = 1 Math.abs( -1 ) = 1 Math.abs( -100.123 ) = 100.123 |
acos | Math.acos( var ) - Arc cosine (in radians). |
asin | Math.asin( var ) - Arc sine (in radians). |
atan | Math.atan( var ) - Arc tangent (in radians). |
atan2 | Math.atan2( var1, var2) - Angle of polar coordinates x and y |
ceil | Math.ceil( var ) - round up to the
next integer. Ex: Math.ceil(1.1) = 2 Math.ceil(1.5) = 2 Math.ceil(1.9) = 2 |
cos | Math.cos( var ) - Cosine |
exp | Math.exp( var ) - Power of |
floor | Math.floor( var ) - round down to the
previous integer. Ex: Math.floor(1.1) = 1 Math.floor(1.5) = 1 Math.floor(1.9) = 1 |
log | Math.log( var ) - Natural logarithm. |
max | Math.max( var1, var2) - Returns the
greater value of the arguments. Ex: Math.max( 1.1, 1.5) = 1.5 |
min | Math.min( var1, var2) - Returns the
lesser value of the arguments. Ex: Math.min( 1.1, 1.5) = 1.1 |
pow | Math.pow(var1, var2) - Returns var1 to
the power of var2. Ex: Math.pow(10,2) = 100 |
random | Math.random() - Returns a Random
number between 0 and 1. Ex: Math.random() = 0.18925420584172098 Math.random() = 0.5879989492922739 Math.random() = 0.03670801222553011 Example of generating a random
number between 1 and 6 (rolling dice) |
round | Math.round( var ) - Returns the
rounded integer. ( >= .5 will be the next integer). Ex: Math.round(1.1) = 1 Math.round(1.5) = 2 Math.round(1.9) = 2 |
sin | Math.sin( var ) - Sin (in radians) |
sqrt | Math.sqrt( var ) - Square root Ex: Math.sqrt(9) = 3 |
tan | Math.tan( var ) - Tangent (in radians) |
Item | Description |
General Information | General Information
|
Relevant functions described in other sections | |
Examples |
|
Create a Date object |
var dateToday = new Date(); var dateHired = new Date("11/01/2007");
|
Year | Year - <YYYY> . If in
1900, then returns date minus 1900 (<Y> or <YY>)
(note: UTC=universal time)
|
Month of year | Month - 0-11 (0=Jan thru 11=Dec)
(note: UTC=universal time)
|
Date in month | Date - 1-31 Date within the month.
(note: UTC=universal time)
|
Day of week |
Day - 0-6 day of week (Sunday=0)
(note: UTC=universal time)
|
Hour of day (24hr) |
Hours - 0-23 Hour of the day in 24
hour format. (note: UTC=universal time)
|
Minute of hour | Minutes - 0-59 Minute
(note: UTC=universal time)
|
Second of minute | Seconds - 0-59 Second (note: UTC=universal
time)
|
Milliseconds of second. | Milliseconds - 0-999 milliseconds
(note: UTC=universal time)
|
Time in Milliseconds | Time - Milliseconds since 1/1/1970
00:00:00 GMT.
|
getTimezoneOffset() | The getTimezoneOffset() method returns
the difference in minutes between Greenwich Mean Time (GMT) and
local time. Example: |
toDateString() | |
toGMTString() | Deprocated. Use: toUTCString() Example: |
toLocalDateString() | |
toLocalTimeString() | |
toLocaleString() | Example: |
toString () | Example: |
toUTCString() | |
Date.UTC() |
Date.UTC(year,month,day,hours,minutes,seconds,ms)
The UTC() method takes a date and returns the number of milliseconds since midnight of January 1, 1970 according to universal time. Example: |
Date.parse(strDate) | Date.parse(datestring) Returns the # of milliseconds from 1970/01/01. var d = Date.parse("Jul 10, 2008"); |
dateObject.valueOf() | Returns the primitive value of a Date object which is usually the Milliseconds since 1/1/1970 00:00:00 GMT. |
Work around: Subtract Days |
var dateReportStart = new Date(); var dateReportStop = new Date(); dateReportStart.setDate(dateReportStart.getDate()-14); //Default to 2 weeks back. ex: Start: 04/22/2009; Stop: 05/06/2009 |
Convert dateObject to dateObject with UTC value. | With server side JavaScript when you
read in a UTC date from a database into a date object it will
display in the date/time of the server unless you use the UTC
functions. If you don't want to use the UTC functions then use
this to convert the date object to a UTC date object.
dateTesting = new Date(); Results: |
Item | Description |
Relevant functions described in other sections | |
Array | Array
var arrTemp = ["Item 1", "Item 2", "Item 3"];
var arrDateDaysFull = ["Sunday", "Monday", "Tuesday",
"Wednesday", "Thursday", "Friday", "Saturday"]; |
Array Properties | Array Properties
|
concat() | |
join() | |
push() | |
pop() | |
reverse() | |
shift() | |
slice() | |
sort() | |
unshift() | |
split() | Converts a string to an array. <Array> = String.split(<string for the separator value>) Returns: Array Ex 1: Return an array of the cookie values: (the separator value is "; ") var arrCookieInfo = document.cookie.split("; "); |
Need to check on: arrMy.contains(<string value>) |
Number Object | The Number Object is normally not
needed because the native number in JavaScript can accomplish almost
all of your needs. var objMyNumber = new Number( 10 ); Number.MAX_VALUE |
Boolean Object | The Boolen Object is normally not
needed because the native number in JavaScript can accomplish almost
all of your needs. var objMyBoolean = new boolean(true); Boolean.toString() Also has a prototype property. |
Custom Object | Custom Object - create your own object
with properties. var objTest = { objTest.strTest = Hello for (property in update)
{ |
Function | Description |
<object>.toString() | <object>.toString() Returns a string value representing the value of the object. ex: <array object>.toString() - returns a comma-delimited string of the contents. |
Window | Window Object
|
abstract boolean break byte case catch char class const continue default delete do double |
else extends false final finally float for function goto if implements import in instanceof |
int interface long native new null package private protected public return short static super |
switch
synchronized this throw throws transient true try typeof var void while with |
Item | Description |
Under Construction |
action alert alinkColor anchor method Anchor object anchors appCodeName Applet applets appName appVersion Area arguments array arguments property Array back bgColor big blink blur bold Boolean border Button caller charAt Checkbox checked clearTimeout click close (document object) close (window object) closed complete confirm constructor cookie current Date defaultChecked defaultSelected defaultStatus defaultValue description document domain E elements array elements property embeds array enabledPlugin encoding escape eval fgColor filename FileUpload fixed focus fontcolor fontsize Form object form property forms forward Frame frames Function go hash height Hidden history array history object host hostname href hspace Image images index italics javaEnabled lastIndexOf lastModified length link method Link object linkColor links LN2 LN10 location LOG2E LOG10E lowsrc Math MAX_VALUE method MimeType mimeTypes MIN_VALUE name NaN navigator NEGATIVE_INFINITY next Number onAbort onBlur onChange onClick onError onFocus onLoad onMouseOut onMouseOver onReset onSelect onSubmit onUnload open (document object) open (window object) opener Option options parent parse parseFloat Password pathname PI Plugin plugins port POSITIVE_INFINITY previous prompt protocol prototype Radio referrer refresh reload replace reset method Reset object scroll search select method Select object selected selectedIndex self small split SQRT1_2 SQRT2 src status strike String sub submit method Submit object suffixes sup taint taintEnabled target Text object text property Textarea title top type |