See also: HTML
To enable client-side debugging:
The debugger can be activated using the JScript equivalent of "int 3":
debugger
e.g. if i==0 debugger;
Normal break points (red dots introduced by clicking in the margin of the source code) do not appear to work (lasted checked: RC2)
Standard C++ comment characters can be used within the <Script> block.
The datatype (or more correctly, to object from which the variable was constructed) is held in the constructor property. For example, if (myVar.constructor == String) alert("Its a string!").
Arrays
Arrays can store any type (and combination of types). The declaration syntax is:
- var myArray = new Array()
- var myArray = new Array(size)
- var myArray = new Array(element1, element2, ..., elementN)
- var myArray: Array = [element1, element2, ..., elementN]
- var i : int[] = new int[ size ];
- var i : int[,] = new int[ size, size ]
for example,
var someDetails = new Array("Dave", 30, Date());Although arrays can be declared with round brackets, they can only be accessed through square brackets, e.g. fred[2] = 10;
Dates
Constructors:
- var myVar = new Date()
Constructs with current date-time
- var myVar = new Date(Year, Month, Day [, Hour, Minute, Seconds, ...]
Constructs the date-time using the specified valuesThere is no "get friendly format" functions. For example, there is no "get month name from month number"
Not that the getMonth() function is 0 based, yet the constructor is 1 based.
Strings
Length: Use the length property (no len(...) fn)
Case: .toUpperCase() and .toLowerCase(). (no toProperCase())
Splice & Dice:
- .charCodeAt( [index] )
ASCII code at position index or 0 if index not supplied
- .fromCharCode( index [, index [, ...]] )
Returns a new string made up from the characters at the specified index positions in the source string
- .concat( string )
"+=" equivalent (+= is also supported by the way)
- .indexOf( searchString [, startIndex] )
.search( regularExpression )
indexOf is quivalent to "AT()" equivalent except strings are 0 based and "no match" returns -1. search uses a regular expression instead of a literal string.
- .match( regularExpression )
Returns an array if one or matches are found, else returns null.
- .replace( regularExpression, replacementString )
Replaces all expressions that match regularExpression in the original string with replacementString
- .splice( [stringOrRegularExpression [, arraySizeLimit ]] )
Returns an array from the string by using stringOrRegularExpression as a deliminator. If stringOrRegularExpression is not supplied an array of characters are returned. If its a single space, whitespace is "compressed" in the return (for example "space-space-tab" would be treated as a single break between values)
- .slice( startIndex [,endIndex] )
.substr( startIndex [, length] )
.substring( startIndex, endIndexPlusOne )
.substring( endIndex, startIndexPlusOne )
Returns the specified portion of the string
Encoding/decoding
- escape(string)
unescape(string)
Convert to and from "%" format (e.g. "Hello World" <--> "Hello%20World")Other:
- HTML formating: .bold(), .italic(), etc.
Code(s) Meaning \b \B Word boundary / not word boundary \d \D Decimal (0-9) / not decimal \s \S Single whitespace character / single non-whitespace character \w \W Alphanumerical (i.e. not symbolic) or underscore / doesn't match \w [xyz] [^xyz] Any of the characters represented in xyz / anything but the characters represented in xyz . Not newline / end of line? For example: /\b[AB]C\b/
means: All occurrences of the words AB and AC
Code Meaning * Match expression zero or more times ? Match expression zero or once + Match expression one or more times {n} Match expression exactly n times {min,} Match expression min or more times {min, max} Match expression between at least min times, but no more than max times For example: /abc*de?/
means: All strings that begin with "ab" followed immediately by zero or more "c"s followed immediately by a "d" followed immediately by no more that one (possibly by zero) "e"s.
Code Meaning ^ Match expression that follows with beginning of lines only $ Match expression that follows with end of lines only | Match expression to the left or to the right (Note that this is a single "|" rather than JScripts normal "||" (expression) A bracketed expression will be included as an extra matching section in the results array For example: /^Test/
matches: "Testing 1 2 3" but not "England have lost the 2nd Test"For example: /(d)(d)(d)/ on "123"
returns an array of 3 elements {"1","2","3"} while /ddd/ (which we'd normally express as /d{3}/ returns an array of 1 element containing "123"
Comparisons in switch statements are "= = =" rather than "= =", so types must match as well as values.
Case statements cannot contain multiple values (e.g. case 1,2,4:). If they do, they do not error but none of the values in the list are checked. Use "fall through" instead (e.g. case 1: case 2: case 4: <code> break;)