JScript

See also: HTML

Debugging

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)

 

Commenting

Standard C++ comment characters can be used within the <Script> block.

 

Datatypes

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:

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:

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

Encoding/decoding

Other:

 

Regular Expression Matching

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"

 

Switch Statements

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;)

 

Events

 

Classes

 

Timers

 

Document Handlers