Microsoft® JScript Language Reference

Microsoft® JScript™
Advantages of CHM 		JScript Tutorial
Version Information

What are the advantages of having this reference in a CHM file?

  1. It is only one file, not more than 930!
  2. Reduced file size! On a 1.2 GB HD with the FAT16 file system, this reference would use 30 MB of HD space, even though there is only 1.6MB of files! Ona 2+ GB HD, it would take 60 MB! On a 4+ GB HD it would take an amazing 120 MB for only 1.6 MB of files. There are some serious space savings to be made there!
  3. Easy to use menu.
  4. This file is much less than the distribution file from the Microsoft site, and is still in a useable format.
  5. Files are compressed to 15% of their original size, saving even more disk space.
  6. You stilll get al lthe features of IE4, such as ActiveX, VBScript, JavaScript plus more in CHM files.
  7. CHM will be the new help format for Windows 98.

And the disadvantages?

  1. You need either Microsoft Internet Explorer 4 on Windows 95, or Windows 98 to view it.
  2. It is harder to extract sepcific information, although easier to find it first.
  3. Files are compressed so time is used to uncompress them.


Microsoft® JScript Language Reference

Microsoft® JScript™
Copyright Information 		JScript Tutorial
Version Information

This Reference has been compiled to a CHM file by Andrew Tait atait@netc.net.au . I do not claim that I wrote this documentation, I only compiled it for convenience. This reference is Copyright © 1997 Microsoft Corporation. All rights reserved.

I am not charging anything for this, I compiled it for my own convenience, and decided to distribute it to other so they could experience the convenience too.


Microsoft® JScript Language Reference

Microsoft® JScript™
Introduction 		JScript Tutorial
Version Information

On with the Reference...

This Reference has been compiled to a CHM file by Andrew Tait atait@netc.net.au . I do not claim that I wrote this documentation, I only compiled it for convienience. This reference is Copyright © 1997 Microsoft Corporation. All rights reserved.

Why did I compile it you ask? Well all the seperate HTML files took 30 MB on my Hard Disk, even though there is only 1.59 MB of files. That it due to my cluster size of 32 KB and FAT16 file system. Don't worry if you don't understand. Compiling it saved more than 29 MB on my Hard Drive, plus make it easier to use.

Other reference are also avaliable on my home page at http://home.netc.net.au/~atait/ so check it out some time. If you need any programming done for your web site, feel free to contact me to find the best solution for you.

I have fixed some minor errors in here, such as invalid links and incorrect font tags. I have only added three pagess to this reference, Introduction (this page), Advantages and Copyright . I have not touched any other part of this document except to fix minor errors.

This CHM file was made with the HTML Help Construction Workshop .

A great companion to this is the ActiveX Control Pad, which will assist you in VBScript and JavaScript Programming. Find it at http://www.microsoft.com/workshop/author/ .

Good Luck,

Andrew Tait atait@netc.net.au .

On with the Reference...


What Is JScript?

Microsoft® JScript™
What Is JScript?
 JScript Tutorial
Next

JScript is the Microsoft implementation of the ECMA 262 language specification. It is a full implementation, plus some enhancements that take advantage of capabilities of Microsoft Internet Explorer. This tutorial is intended to help you get started with JScript.

Easy to Use, Easy to Learn
JScript is an interpreted, object-based scripting language. Although it has fewer capabilities than full-fledged object-oriented languages like C++ and Java, JScript is more than sufficiently powerful for its intended purposes.

JScript is not a cut-down version of any other language (it is only distantly and indirectly related to Java, for example), and it is not a simplification of anything. It is, however, limited. You cannot write standalone applications in it, for example, and it has little capability for reading or writing files. Moreover, JScript scripts can run only in the presence of an interpreter, either in a Web server or a Web browser.

JScript is a loosely typed language. That means you do not have to declare the data types of variables explicitly. Moreover, in many cases JScript performs conversions automatically when they are needed. For instance, if you try to add a number to an item that consists of text (a string), the number is converted to text.

The rest of this tutorial is an overview of JScript features. For full details of the language implementation, consult the language reference.

Note The code in many of this tutorial's examples is somewhat more explicit and less dense than code you'll find in actual Web pages. Most of it is also fairly simple. The intent here is to clarify the concepts, not to express optimal coding conciseness and style. There is, in any case, no shame in writing code that you can read and easily understand, six months after you write it.

© 1997 Microsoft Corporation. All rights reserved. Terms of Use.


Using Message Boxes

Microsoft® JScript™
Using Message Boxes
 JScript Tutorial
Previous

Using alert, prompt, and confirm
Use alert, confirm, and prompt message boxes to obtain input from your user. The boxes are methods of the interface window object. Because the window object is at the top of the object hierarchy, you do not actually have to use the full name (for example, "window.alert()") of any of these message boxes, but it is a good idea to do so, because it helps you remember to which object they belong.

Alert Message Box
The alert method has one argument, the string of text you want to display to the user. The string is not HTML. The message box provides an OK button so the user can close it and is modal, that is, the user must close the message box before continuing.

window.alert("Welcome! Press OK to continue.");
Confirm Message Box
The confirm message box lets you ask the user a "yes-or-no" question, and gives the user the option of clicking either an OK button or a Cancel button. The confirm method returns either true or false.

This message box is also modal: the user must respond to it (click a button), and thereby close it, before proceeding.

var truthBeTold = window.confirm("Click OK to continue. Click Cancel to stop.");
if (truthBeTold) {
window.alert("Welcome to our Web page!");
}  else  window.alert("Bye for now!");
Prompt Message Box
The prompt message box provides a text field in which the user can type an answer in response to your prompt. This box has an OK button and a Cancel button. If you provide a second string argument, the prompt message box displays that second string in the text field, as the default response. Otherwise, the default text is "<undefined>".

Like the alert( ) and confirm( ) methods, prompt displays a modal message box. The user must close it before continuing.

var theResponse = window.prompt("Welcome?","Enter your name here.");


Intrinsic Objects

Microsoft® JScript™
Intrinsic Objects
 JScript Tutorial
Previous

Microsoft JScript provides nine intrinsic (or "built-in") objects. They are the Array, Boolean, Date, Function, Global, Math, Number, Object, and String objects. Each of the intrinsic objects has associated methods and properties that are described in detail in the language reference. Certain of the objects are also described here.

Array Object
In JScript, objects are handled as arrays and arrays are handled as objects. The subscripts of an array, which are entirely equivalent to the properties of an object, can be referred to by number (or by name, if you assign names to them). To create a new array, use the new operator and the Array() constructor, as in the following example.

var theMonths = new Array(12)  {
theMonths[0] = "Jan";
theMonths[1] = "Feb";
theMonths[2] = "Mar";
theMonths[3] = "Apr";
theMonths[4] = "May";
theMonths[5] = "Jun";
theMonths[6] = "Jul";
theMonths[7] = "Aug";
theMonths[8] = "Sep";
theMonths[9] = "Oct";
theMonths[10] = "Nov";
theMonths[11] = "Dec";
}
When you create an array by using the Array keyword, JScript includes in the array a write-only length property, which records the number of entries in the array. If you do not specify a number, the length is set to 0, and the array has no entries. If you specify a number, the length is set to that number. If you specify more than one parameter, the parameters are used as entries in the array, and the number of parameters is assigned to the length property, as in the following example, which is equivalent to the preceding one.

var theMonths = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
JScript automatically changes the value of length if you add elements to an array that you have created with the Array keyword.

String Object
In JScript, strings are objects. This means that any time you declare a string variable or use a string literal, what you're actually doing is creating a new string object. The String object has certain built-in methods, which you can use with your strings. One of these is the substring method, which returns part of the string. It takes two numbers as its arguments.

aString = "0123456789";
var aChunk = aString.substring(4, 7);  // Sets aChunk to "456".
var aNotherChunk = aString.substring(7, 4);  // Sets aNotherChunk to "456".

// Using the preceding Array creation example:
firstLetter = theMonths [5].substring(0,1);  // Sets the firstLetter variable to "J".
Another property of the String object is the length property. This property contains the number of characters in the string, which is 0 for an empty string. This a numeric value, and can be used directly in calculations.
var howLong = "Hello World".length  // Sets the howLong variable to 11.
Math Object
The Math object has a number of properties and methods, all predefined. The properties are specific numbers. One of these is the value of pi (approximately 3.14159...). This is the Math.PI property, shown in the following example.

// A radius variable is declared and assigned a numeric value.
var circleArea = Math.PI * radius * radius;  // Note capitalization of Math and PI.
One of the built-in methods of the Math object is the exponentiation method, or pow, which raises a number to a specified power. The following example makes use of both pi and exponentiation.

// This formula calculates the volume of a sphere with the given radius.
volume = (4/3)*(Math.PI*Math.pow(radius,3));
Date Object
Use the Date object to capture today's date, and to calculate differences between dates. It has a number of properties and methods, all predefined. In general, the Date object provides the day of the week; the month, day, and year; and the time in hours, minutes, and seconds.

This information is based on the number of milliseconds since January 1, 1970, 00:00:00.000 GMT. GMT stands for "Greenwich Mean Time"; the preferred term is UTC, or "Coordinated Universal Time," which refers to signals issued by the World Time Standard.

Note As far as JScript is concerned, time begins at midnight on January 1, 1970; you cannot ask JScript to create a Date object that represents an earlier time than that. If you need to deal with earlier times you must write your own code to do so, a formidable task.

To create a new Date object you use the new operator. The following example calculates, for the current year, the number of days that have passed and the number of days that are left.

/*
This example uses the array of month names defined previously.
The first statement assigns today's date, in "Day Month Date 00:00:00 Year"
format, to the thisIsToday variable.
*/
var thisIsToday = new Date();

var toDay = new Date();  // Capture today's date.

// Extract the year, the month, and the day.
var thisYear = toDay.getYear() + 1900;
var thisMonth = theMonths[toDay.getMonth()];
var thisDay = thisMonth  + " " + toDay.getDate() + "," + (parseInt(toDay.getYear()) + 1900);

// Determine the # of days since the start.
thisDay = Math.round(Date.parse(thisDay)/8.64e7);

// Do the same for the beginning of the year.
var firstDay = "Jan 1, " + thisYear;
firstDay = Math.floor(Date.parse(firstDay)/8.64e7);

// Do it again for the end of the year, in case it's a leap year.
var lastDay = "Dec 31, " + thisYear;
lastDay = Math.floor(Date.parse(lastDay)/8.64e7);

// Compute the number of days in the year.
var daysInYear = (lastDay - firstDay) + 1;

// Determine how many days have elapsed, and how many are left.
var daysElapsed = thisDay - firstDay;
var daysLeft = daysInYear - daysElapsed;

// Set up comments for most of the year.
var comment1 = daysElapsed+ " days have elapsed in the year.";
var comment2 = "That means there are " + daysLeft + " days left in " + thisYear + ".";

// Cover the special cases: beginning & end of year, and single day.
if (daysElapsed == 0)  {
comment1 = "It's January first, " + thisYear + ".";
}
if (daysElapsed == 1) {
comment1 = "Only one day gone so far.";
}
if(daysElapsed == daysInYear) {
comment1 = thisYear + " is just about over.";
}

if (daysLeft == 0)  {
comment2 = "Best wishes for the New Year!";
}
if (daysLeft == 1)  {
comment2 = "There's only one day left in " + thisYear + ".";
}
if (daysLeft == daysInYear)  {
comment2 = "Happy New Year!";
}
Number Object
In addition to the special numeric properties (PI, for example) that are available in the Math object, several other properties are available in Microsoft JScript through the Number object.

Property | Description
MAX_VALUE Largest possible number, about 1.79E+308; can be positive or negative. (Value varies slightly from system to system.)
MIN_VALUE | Smallest possible number, about 2.22E-308; can be positive or negative. (Value varies slightly from system to system.)
NaN | Special nonnumeric value, "not a number."
POSITIVE_INFINITY Any positive value larger than Number.MAX_VALUE
is automatically converted to this value; represented as "Inf".
NEGATIVE_INFINITY Any negative value larger than -Number.MAX_VALUE
is automatically converted to this value; represented as "-Inf".

Number.NaN is a special property that is defined as "not a number." Division by zero, for example, returns NaN. An attempt to parse a string that cannot be parsed as a number also returns Number.NaN. NaN compares unequal to any number and also to itself. To test for a NaN result, do not compare against Number.NaN; use the isNaN() function instead.


Troubleshooting Your Scripts

Microsoft® JScript™
Troubleshooting Your Scripts
 JScript Tutorial
Previous
Next

There are places in any programming language where you can get caught if you are not careful, and every language has specific surprises in it. Take, for example, the null value: The one in Microsoft JScript behaves differently than the null value in the C or C++ languages.

Here are some of the trouble areas that that you may run into as you write JScript scripts.

Syntax Errors
Because syntax is much more rigid in programming languages than in natural languages, it is important to pay strict attention to detail when you write scripts. If, for example, you mean for a particular parameter to be a string, you will run into trouble if you forget to enclose it in quotation marks when you type it.
Order of Script Interpretation
JScript interpretation is part of the your Web browser's HTML parsing process. So, if you place a script inside the <HEAD> tag in a document, it is interpreted before any of the <BODY> tag is examined. If you have objects that are created in the <BODY> tag, they do not exist at the time the <HEAD> is being parsed, and cannot be manipulated by the script.

Automatic Type Coercion
JScript is a loosely typed language with automatic coercion. Consequently, despite the fact that values having different types are not equal, the expressions in the following example evaluate to true.
"100" == 100
false == 0
Operator Precedence
When a particular operation is performed during the evaluation of an expression has more to do with operator precedence than with the location of the expression. Thus, in the following example, multiplication is performed before subtraction, even though the subtraction appears first in the expression.
theRadius = aPerimeterPoint - theCenterpoint * theCorrectionFactor;
Using for...in Loops with Objects
When you step through the properties of an object with a for...in loop, you cannot necessarily predict or control the order in which the fields of the object are assigned to the loop counter variable. Moreover, the order may be different in different implementations of the language.
with Keyword
The with statement is convenient for addressing properties that already exist in a specified object, but cannot be used to add properties to an object. To create new properties in an object, you must refer to the object specifically.
this Keyword
Although you use the this keyword inside the definition of an object, to refer to the object itself, you cannot ordinarily use this or similar keywords to refer to the currently executing function when that function is not an object definition. You can, if the function is to be assigned to an object as a method, use the this keyword within the function, to refer to the object.
Writing a Script That Writes a Script
The </SCRIPT> tag terminates the current script if the interpreter encounters it. To display "" itself, rewrite this as at least two strings, for example, "</SCR" and "IPT>", which you can then concatenate together in the statement that writes them out.

Implicit Window References
Because more than one window can be open at a time, any window reference that is implicit is taken to point to the current window. For other windows, you must use an explicit reference.


Controlling Program Flow

Microsoft® JScript™
Controlling Program Flow
JScript Tutorial
Previous
Next

Why Control the Flow of Execution?
Fairly often, you need a script to do different things under different conditions. For example, you might write a script that checks the time every hour, and changes some parameter appropriately during the course of the day. You might write a script that can accept some sort of input, and act accordingly. Or you might write a script that repeats a specified action.

There are several kinds of conditions that you can test. All conditional tests in Microsoft JScript are Boolean, so the result of any test is either true or false. You can freely test values that are of Boolean, numeric, or string type.

JScript provides control structures for a range of possibilities. The simplest among these structures are the conditional statements.

Using Conditional Statements
JScript supports if and if...else conditional statements. In if statements a condition is tested, and if the condition meets the test, some JScript code you've written is executed. (In the if...else statement, different code is executed if the condition fails the test.) The simplest form of an if statement can be written entirely on one line, but multiline if and if...else statements are much more common.

The following examples demonstrate syntaxes you can use with if and if...else statements. The first example shows the simplest kind of Boolean test. If (and only if) the item between the parentheses evaluates to true, the statement or block of statements after the if is executed.

// The smash() function is defined elsewhere in the code.
if (newShip)
   smash(champagneBottle,bow);  // Boolean test of whether newShip is true.

// In this example, the test fails unless both conditions are true.
if (rind.color == "deep yellow " && rind.texture == "large and small wrinkles")
{
        theResponse = ("Is it a Crenshaw melon? <br> ");
}

// In this example, the test succeeds if either condition is true.
var theReaction = "";
if ((lbsWeight > 15) || (lbsWeight > 45))
{
    theReaction = ("Oh, what a cute kitty! <br>");
}
else
    theReaction = ("That's one huge cat you've got there! <br>");
Conditional Operator
JScript also supports an implicit conditional form. It uses a question mark after the condition to be tested (rather than the word if before the condition), and specifies two alternatives, one to be used if the condition is met and one if it is not. The alternatives are separated by a colon.

var hours = "";

// Code specifying that hours contains either the contents of
// theHour, or theHour - 12.

hours += (theHour >= 12) ? " PM" : " AM";

Tip If you have several conditions to be tested together and you know that one is more likely to pass or fail than any of the others, depending on whether the tests are connected with OR (||) or AND (&&), you can speed execution of your script by putting that condition first in the conditional statement. That is, for example, if three conditions must all be true (using && operators) and the second test fails, the third condition is not tested. Similarly, if only one of several conditions must be true (using || operators), testing stops as soon as any one condition passes the test. This is particularly effective if the conditions to be tested involve execution of function calls or other code.

An example of the side effect of short-circuiting is that runsecond will not be executed in the following example if runfirst() returns 0 or false.

if ((runfirst() == 0) || (runsecond() == 0))
  // some code
Using Repetition, or Loops
There are several ways to execute a statement or block of statements repeatedly. In general, repetitive execution is called looping. It is typically controlled by a test of some variable, the value of which is changed each time the loop is executed. Microsoft JScript supports many types of loop: for loops, for...in loops, while loops, do...while loops, and switch loops.

Using for Loops
The for statement specifies a counter variable, a test condition, and an action that updates the counter. Just before each time the loop is executed (this is called one pass or one iteration of the loop), the condition is tested. After the loop is executed, the counter variable is updated before the next iteration begins.

If the condition for looping is never met, the loop is never executed at all. If the test condition is always met, an infinite loop results. While the former may be desirable in certain cases, the latter rarely is, so take care when writing your loop conditions.

/*
The update expression ("icount++" in the following examples)
is executed at the end of the loop, after the block of statements that forms the
body of the loop is executed, and before the condition is tested.
*/

var howFar = 11;  // Sets a limit of 11 on the loop.

var sum = new Array(howFar);  // Creates an array called sum with 11 members, 0 through 10.
var theSum = 0;
sum[0] = 0;

for(var icount = 1; icount < howFar; icount++)  {        // Counts from 1 through 10 in this case.
theSum += icount;
sum[icount] = theSum;
}

var newSum = 0;
for(var icount = 1; icount > howFar; icount++)  {        // This isn't executed at all.
newSum += icount;
}

var sum = 0;
for(var icount = 1; icount > 0; icount++)  {        // This is an infinite loop.
sum += icount;
}
Using for...in Loops
JScript provides a special kind of loop for stepping through all the properties of an object. The loop counter in a for...in loop steps through all indexes in the array. It is a string, not a number.

for (j in tagliatelleVerde)  // tagliatelleVerde is an object with several properties
{
// Various JScript code statements.
}
Using while Loops
The while loop is very similar to a for loop. The difference is that a while loop does not have a built-in counter variable or update expression. If you already have some changing condition that is reflected in the value assigned to a variable, and you want to use it to control repetitive execution of a statement or block of statements, use a while loop.

var theMoments = "";
var theCount = 42;        // Initialize the counter variable.
while (theCount >= 1)  {
    if (theCount > 1)  {
        theMoments = "Only " + theCount + " moments left!";
}
    else  {
        theMoments = "Only one moment left!";
    }
theCount--;        // Update the counter variable.
}
theMoments = "BLASTOFF!";

Note Because while loops do not have explicit built-in counter variables, they are even more vulnerable to infinite looping than the other types. Moreover, partly because it is not necessarily easy to discover where or when the loop condition is updated, it is only too easy to write a while loop in which the condition, in fact, never does get updated. You should be extremely careful when you design while loops.

Using break and continue Statements
Microsoft JScript provides a statement to stop the execution of a loop. The break statement can be used to stop execution if some (presumably special) condition is met. The continue statement can be used to jump immediately to the next iteration, skipping the rest of the code block but updating the counter variable as usual if the loop is a for or for...in loop.

var theComment = "";
var theRemainder = 0;
var theEscape = 3;
var checkMe = 27;
for (kcount = 1; kcount <= 10; kcount++)
{
    theRemainder = checkMe % kcount;
    if (theRemainder == theEscape)
      {
            break;  // Exits from the loop at the first encounter with a remainder that equals the escape.
}
theComment = checkMe + " divided by " + kcount + " leaves a remainder of  " + theRemainder;
}

for (kcount = 1; kcount <= 10; kcount++)
{
   theRemainder = checkMe % kcount;
   if (theRemainder != theEscape)

   {
      continue;  // Selects only those remainders that equal the escape, ignoring all others.
}
// JScript code that uses the selected remainders.
}

var theMoments = "";
var theCount = 42;  // The counter is initialized.
while (theCount >= 1)  {
// if (theCount < 10)  {  // Warning!
// This use of continue creates an infinite loop!
// continue;
// }
    if (theCount > 1)  {
        theMoments = "Only " + theCount + " moments left!";
}
    else  {
        theMoments = "Only one moment left!";
    }
theCount--;  // The counter is updated.
}
theCount = "BLASTOFF!";


Advanced Object Creation

Microsoft® JScript™
Advanced Object Creation
 JScript Tutorial
Previous
Next

Using Constructors to Create Objects
In Microsoft JScript, you use constructors to create and build a class of objects.

You invoke a constructor with the new statement. It returns whatever it constructs.

The special case Function constructor lets you create functions that are anonymous. An anonymous function is one that does not have a name. You can use the Function constructor to build a function "on the fly", for example, as one of the instructions inside another function. Such a function, which is only called from the one location, doesn't need a name.

In the following example, such an anonymous function generates one line of a "name-and-email-address" listing. It checks the value of the firstNameFirst variable to decide whether to put the first name or the last name first, and the value of the emailNameFirst variable to decide whether to put the name or the email address first. The example assumes that the values of firstNameFirst and emailNameFirst are set elsewhere.

for (j = 1; j < addressList[length]; j++)
{
oneListingLine = new Function(emailNameFirst, firstNameFirst, addressList, j, theName = new Function(firstNameFirst, addressList, j, var theName=(addressList[j].firstName + addressList[j].lastName);
if(firstNameFirst)
      {
      theName=(addressList[j].firstName + addressList[j].lastName);
      },) ;
if (emailNameFirst)
      {
theListing = addressList[j].emailName+ ":\t" + theName
      } else theListing = theName + ":\t" + addressList[j].emailName; return theListing;)
document.write(oneListingLine + "<br>");
}
Writing Constructors
To write your own constructors, you use the this keyword within the constructor to refer to the newly-created object. The constructor initializes the object.

Though the constructor in the next example starts at an index of 0, this is not required. You can start with a first index of 1 if, for example, you want a parameter that indicates the actual number of indices of the array or object. In the example, it's called extent to distinguish it from the automatically maintained length parameter of the built-in Array( ) object). If you write code that adds properties to the array, you have to update the extent parameter (or your equivalent) because this parameter is not maintained by JScript. Notice that even this extremely simple example uses both object (dot) and array (bracket) notation styles to refer to the current object.

function MakeStringArray(length) {
this.extent = length;
for (iNum = 0; iNum < length; i++) {
this[iNum] = "";
}
}

// Use the constructor to create and initialize an array.
myStringArray = new MakeStringArray(63);
Using Prototypes to Create Objects
When you write an object definition, you can use prototype properties to create properties that are held in common by all objects that are generated by the definition. Prototype properties are copied by reference into each object of a class, so they have the same value for all objects in the class. However, you can change the value of a prototype property in one object, and the new value overrides the default, but only in that one instance. Other objects that are members of the class are not affected by the change.

Using this principle, you can define additional properties for objects that are part of the JScript language, which all have prototypes. For example, if you want a special constant for a calculation, and the constant is not among those provided in the Math and Number objects, you can define it yourself and then assign it their respective object prototypes, or the prototype property of your object class.

Math.prototype.Avogadro = 6.0232E23;
function howManyMolecules(wtGrams,molWt) {
return ((wtGrams/molWt)*Math.prototype.Avogadro);
}
document.write("There are " + howManyMolecules(window.prompt("How many grams?",0),window.prompt
("What's the molecular weight?",0)) +
 " molecules in that amount.");
Perhaps more to the point, you can define a function, assign it to String.prototype as a method, and use it on any string anywhere in your script. The following example assumes the existence of a Periodic Chart array called "theElements", defined elsewhere in the script, which contains symbols for the elements, their names, their atomic weights, and other relevant information about them.

function atomName(theSymbol) {
return(theElements[theSymbol].fullName);
}

String.prototype.atomName = atomName;

function decodeFormula(theFormula) {
var theCurrentPiece = "";
var theDecodedFormula = "";
for (i = 1; i = theFormula.length ; i++);
if (theFormtheCurrentPiece
// Code statements to separate the formula string into an array of symbols and numbers.
// Loop through the formula array and assemble the decoded string. Each term is:
theDecodedFormula += formula[n].number
theDecodedFormula += " ";
theDecodedFormula += formula[n].symbol.prototype.atomName;
theDecodedFormula += " "
// End of loop.

return theDecodedFormula;
}

decodeFormula(window.prompt("Formula?","Al2O3"));


Creating Your Own Objects

Microsoft® JScript™
Creating Your Own Objects
 JScript Tutorial
Previous

To create instances of an object, you must first define it by giving it properties and, if appropriate, methods. For instance, the following example defines a pasta object. Notice the keyword this, which you use to refer to the current object.

function pasta( grain, grain2, width, shape, shapenum, extent, egg )
{
  this.length = 7;   // Number of properties in the object, not including this one.
  this.grain = grain;   // What grain is it made of? (string)
  this.grain2 = grain2;   // Any other flour in it? (string)
  this.width = width;     // How wide is it? (number)
  this.shape = shape;   // What is the cross-section? (string)
  this.shapenum = shapenum;  // Is it one of the registered shapes? (number)
  this.extent = extent;    // How long is it? (number)
  this.egg = egg;  // Does it have egg yolk as a binder? (Boolean)
}
Once you've defined an object, you create instances of it with the new operator.

var spaghetti = new pasta("wheat", "", 0.2, "circle", 9, 30, true);
var linguine = new pasta("wheat", "", 0.3, "oval", 17, 30, true);
You can add properties to one instance of an object, to change that instance, but those properties do not become part of the definition of the object, and do not show up in other instances unless you specifically add them. If you want the extra properties to show up in all instances of the object, you must add them to the object definition.

// Additional properties for spaghetti.
spaghetti.color = "pale straw";
spaghetti.drycook = 7;
spaghetti.freshcook = 0.5;

var chowFun = new pasta("rice", "", 3, "flat", , 12, false);
/*
Neither the chowFun object, the linguine object, nor the pasta object definition
has the three extra properties given to the spaghetti object.
*/
Including Methods in the Definition
It is possible to include methods in the definition of an object. The following example builds an object that consists of an array of strings, and a method. The method adds a string to the array, increasing its size in order to do so. Notice that this makes each instance of the object indefinitely extensible.

function addItem(newItem)  // Define a function to extend the list.
{
    this.length += 1;  // Increment the length of the array.
    this[(this.length-1)] = newItem;  // Add the new item, maintaining item numbering.
}

function shoppingList(firstItem) // Define a "shopping list" object.
{
    this.length = 2;  // Number of properties in the object, not including this one.
    this.addItem = addItem;   // Include the addItem function as a method.
    this[(this.length-1)] = firstItem;  // The first item is numbered 1.
}

var myList = new shoppingList("Milk");
myList.addItem("Eggs");  // Use the method to add Eggs, which become item 2.
myList.addItem("Breadfruit");  // Breadfruit becomes item 3.
At this point, the contents of the array are as follows:
  • myList[length] is 4
  • myList[addItem] is the addItem function
  • myList[1] is Milk
  • myList[2] is Eggs
  • myList[3] is Breadfruit
Note that the indexing is not exactly as you might expect it to be if it were handled in a strictly numeric way. If you execute a for...in loop on this array, the loop iterates in the order given here, and the loop variable has the initial value "length" rather than 0.


JScript Data Types

Microsoft® JScript™
JScript Data Types
JScript Tutorial
Previous
Next

What Are the JScript Data Types?
Microsoft JScript has six types of data. The main types are numbers, strings, objects, and Booleans. The other two are null and undefined
String Data Type
Strings are delineated by single or double quotation marks. (Use single quotes to type strings that contain quotation marks.) A string is also an object in JScript, but it is a special case, with special properties,. The following are examples of strings:

"The cow jumped over the moon."
'"Avast, ye lubbers!" roared the technician.'
"42"
A string can contain zero or more unicode characters. When it contains zero, it is called a zero-length string ("").
Number Data Type
JScript supports both integer and floating-point numbers. Integers can be positive, 0, or negative; a floating-point number can contain either a decimal point, an "e" (uppercase or lowercase), which is used to represent "ten to the power of" in scientific notation, or both. These numbers follow the IEEE 754 standard for numerical representation. Last, there are certain number values that are special:
  • NaN, or not a Number
  • Positive Infinity
  • Negative Infinity
  • Positive 0
  • Negative 0

Integers can be represented in base 10 (decimal), base 8 (octal), and base 16 (hexadecimal).

Octal integers are specified by a leading "0", and can contain digits 0 through 7. If a number has a leading "0" but contains the digits "8" and/or "9", it is a decimal number. A number that would otherwise be an octal number but contains the letter "e" (or "E") generates an error.

Hexadecimal ("hex") integers are specified by a leading "0x" (the "X" can be uppercase or lowercase) and can contain digits 0 through 9 and letters A through F (either uppercase or lowercase). The letter "e" is a permissible digit in hexadecimal notation and does not signify an exponential number. The letters A through F are used to represent, as single digits, the numbers that are 10 through 15 in base 10. That is, 0xF is equivalent to 15, and 0x10 is equivalent to 16.

Octal and hexadecimal numbers can be negative, but cannot be fractional. A number that begins with a single "0" and contains a decimal point is a decimal floating-point number; if a number that begins with "0x" or "00" contains a decimal point, anything to the right of the decimal point is ignored.

Some example numbers:

.0001, 0.0001, 1e-4, 1.0e-4  // Four floating-point numbers, equivalent to each other.
3.45e2                       // A floating-point number, equivalent to 345.
42                           // An integer number.
0377                         // An octal integer, equivalent to 255.
00.0001                      // As octal numbers cannot have decimal parts, this is equivalent to 0.
0378                         // An integer, equivalent to 378.
0Xff                         // A hexadecimal integer, equivalent to 255.
0x37CF                       // A hexadecimal integer, equivalent to 14287.
0x3e7                        // A hexadecimal integer, equivalent to 999.
0x3.45e2                     // As hexadecimal numbers cannot have decimal parts, this is equivalent to 3.
Booleans

The possible Boolean values are true and false. These are special values, and are not usable as 1 and 0.

Note In a comparison, any expression that evaluates to 0 is taken to be false, and any statement that evaluates to a number other than 0 is taken to be true. Thus the following expression evaluates to true:

(false == 0)
For more information on comparisons, see Controlling Program Flow.

Undefined Data Type
A value that is undefined is simply a value given to a variable after it has been created, but before a value has been assigned to it.
Null Data Type
A null value is one that has no value and means nothing.


JScript Variables

Microsoft® JScript™
JScript Variables
JScript Tutorial
Previous
Next

Variables are used in Microsoft JScript to store values in your scripts. They are a way to retrieve and manipulate values using names. When used effectively then can help in understanding what a script does.

Declaring Variables

Although not required, it is considered good practice to declare variables before using them. You do this using the var statement. The only time you must use the var statement is when declaring variables that are local to a function. At all other times, using the var statement to declare variables before their use is a recommended practice.

The following code examples are of variable declaration:

var mim = "A man, a plan, a canal, Panama!";  // The value stored in mim is of string type.
// The sentence in quotes, the value of which is assigned to mim, is a string literal.

var ror = 3;        // The value stored in ror has numeric type.
var nen = true;        // The value stored in nen has Boolean type.

var fif = 2.718281828        // The value stored in fif has numeric type.

Naming Variables

JScript is a case-sensitive language, so naming a variable myCounter is different from naming it MYCounter. In addition, variable names, which can be of any length, must follow certain rules:

  • The first character must be a letter (either uppercase or lowercase) or an underscore (_), or a dollar sign ($).
  • Subsequent characters can be letters, numbers, underscores, or dollar signs.
  • The variable name can't be a reserved word.

Some examples of valid variable names:

  • _pagecount
  • Part9
  • Number_Items

Some invalid variable names:

  • 99Balloons // Starts with a number.
  • Smith&Wesson // Ampersand (&) is not a valid character for variable names.
In instances in which you want to declare a variable and initialize it, but without giving it any particular value, you may assign it a special value, null.

var zaz = null;
var notalot = 3 * zaz;        // At this point, notalot becomes 0.
If you declare a variable without assigning any value to it, it exists but is undefined.

var godot;
var waitingFor = 1 * godot;  // Places the value NaN in waitingFor as godot is undefined.
You can declare a variable implicitly (without using var) by assigning a value to it. You cannot, however, use a variable that has never been declared at all. To do so generates an error at runtime.

lel = "";  // The variable lel is declared implicitly.

var aMess = vyv + zez;  // Generates an error because vyv and zez don't exist.
Coercion
As JScript is a loosely-typed language, variables in JScript technically have no fixed type. Instead, they have a type equivalent to the type of the value they contain. It is possible, under some circumstances, to force the automatic conversion (or coercion) of a variable or a piece of data into a different type. Numbers can easily be included in strings, but strings cannot be included directly in numbers, so explicit conversion functions, parseInt() and parseFloat(), are provided.

var theFrom = 1;
var theTo = 10;
var doWhat = "Count from ";
doWhat += theFrom + " to " + theTo + ".";
After this code is executed, the doWhat variable contains "Count from 1 to 10." The number data have been coerced into string form.

var nowWhat = 0;
nowWhat += 1 + "10";  // In this case, because "10" is a string,
            // the "+=" operator concatenates.
After this code is executed, the nowWhat variable contains "0110". The following steps are followed to arrive at this result:
  1. Look at the types of 1 and "10". The "10" is a string, the 1 is a number, so the number is coerced into a string.
  2. As the values on either side of the + operator are both strings, do a string concatenation. This results in "110"
  3. Look at the types of the values on either side of the +=. nowWhat contains a number, and "110" is a string, so convert the number to a string.
  4. As there are now strings on either side of the += operator, do a string concatentation. This results in "0110".
  5. Store this result in nowWhat.

var nowThen = 0;
nowThen += 1 + parseInt("10");        // In this case, "+=" performs addition.
After this code is executed, the nowThen variable contains the integer 11.


JScript Functions

Microsoft® JScript™
JScript Functions
 JScript Tutorial
Previous
Next

What Is a Function?
Microsoft JScript functions perform actions. They can also return results. Sometimes these are the results of calculations or comparisons.

Functions combine several operations under one name. This lets you streamline your code. You can write out a set of statements, name it, and then execute the entire set any time you want to, just by calling it and passing to it any information it needs.

You pass information to a function by enclosing the information in parentheses after the name of the function. Pieces of information that are being passed to a function are called arguments or parameters. Some functions don't take any arguments at all; some functions take one argument; some take several. There are even functions for which the number of arguments depends on how you are using the function.

JScript supports two kinds of functions: those that are built into the language, and those you create yourself.

Special Built-in Functions
The JScript language includes several built-in functions. Some of them let you handle expressions and special characters, and convert strings to numeric values.

For example, escape() and unescape() are used to convert characters that have special meanings in HTML code, characters that you cannot just put directly into text. For example, the angle brackets, "<" and ">", delineate HTML tags.

The escape function takes as its argument any of these special characters, and returns the escape code for the character. Each escape code consists of a percent sign (%) followed by a two-digit number. The unescape function is the exact inverse. It takes as its argument a string consisting of a percent sign and a two-digit number, and returns a character.

Another useful built-in function is eval(), which evaluates any valid mathematical expression that is presented in string form. The eval() function takes one argument, the expression to be evaluated.

var anExpression = "6 * 9 % 7";
var total = eval(anExpression);        // Assigns the value 5 to the variable total.
var yetAnotherExpression = "6 * (9 % 7)";
total = eval(yetAnotherExpression)        // Assigns the value 12 to the variable total.

var totality = eval("...surrounded by acres of clams.");        // Generates an error.
Consult the language reference for more information about these and other built-in functions.

Creating Your Own Functions
You can create your own functions and use them where you need them. A function definition consists of a function statement and a block of JScript statements.

The checkTriplet function in the following example takes as its arguments the lengths of the sides of a triangle, and calculates from them whether the triangle is a right triangle by checking whether the three numbers constitute a Pythagorean triplet. (The square of the length of the hypotenuse of a right triangle is equal to the sum of the squares of the lengths of the other two sides.) The checkTriplet function calls one of two other functions to make the actual test.

Notice the use of a very small number ("epsilon") as a testing variable in the floating-point version of the test. Because of uncertainties and roundoff errors in floating-point calculations, it is not practical to make a direct test of whether the square of the hypotenuse is equal to the sum of the squares of the other two sides unless all three values in question are known to be integers. Because a direct test is more accurate, the code in this example determines whether it is appropriate and, if it is, uses it.

var epsilon = 0.0000000000001;  // Some very small number to test against.
var triplet = false;

function integerCheck(a, b, c)  {  // The test function for integers.
    if ( (a*a) == ((b*b) + (c*c)) )  {  // The test itself.
    triplet = true;
    }
}  // End of the integer checking function.

function floatCheck(a, b, c)  {  // The test function for floating-point numbers.
var theCheck = ((a*a) - ((b*b) + (c*c)))  // Make the test number.
    if (theCheck < 0)  {  // The test requires the absolute value, so invert theCheck if it's negative.
    theCheck *= -1;
    }
    if (epsilon > theCheck)  {  // If it's as close as that, it's pretty darn close!
    triplet = true;
    }
}  // End of the floating-poing check function.

function checkTriplet(a, b, c)  {  // The triplet checker. First, move the longest side to position "a".
var d = 0;  // Create a temporary holding bin.
    if (c > b)  {  // If c > b, swap them.
    d = c;
    c = b;
    b = d;
    }  // If not, ignore them.
    if (b > a)  {  // If b > a, swap them.
    d = b;
    b = a;
    a = d;
    }  // If not, ignore them.

// Side "a" is now the hypotenuse, if there is one.

    if (((a%1) == 0) && ((b%1) == 0) && ((c%1) == 0))  {  // Test all 3 values. Are they integers?
    integerCheck(a, b, c);  // If so, use the precise check.
    }
    else
        floatCheck(a, b, c);  // If not, get as close as is reasonably possible.
}  // End of the triplet check function.

// The next three statements assign sample values for testing purposes.
var sideA = 5;
var sideB = 5;
var sideC = Math.sqrt(50);

checkTriplet(sideA, sideB, sideC);  // Call the function. After the call, triplet contains the result.


JScript Glossary

Microsoft® JScript™
JScript Glossary 		Language Reference

ASCII Character Set
American Standard Code for Information Interchange (ASCII) 7-bit character set widely used to represent letters and symbols found on a standard U.S. keyboard. The ASCII character set is the same as the first 128 characters (0–127) in the ANSI character set.

Automation object
An object that is exposed to other applications or programming tools through Automation interfaces.

bitwise comparison
A bit-by-bit comparison of identically positioned bits in two numeric expressions.

Boolean expression
An expression that evaluates to either true or false. Non-Boolean expressions are converted to Boolean values, when necessary, according to the following rules:
  • All objects are considered true.
  • Strings are considered false if and only if they are empty.
  • null and undefined are considered false.
  • Numbers are considered false if and only if they are zero.

character code
A number that represents a particular character in a set, such as the ASCII character set.

class
The formal definition of an object. The class acts as the template from which an instance of an object is created at run time. The class defines the properties of the object and the methods used to control the object's behavior.

comment
Text added to code by a programmer that explains how the code works. In JScript, a comment line generally starts with //. Use the /* and */ delimiters to create a multiline comment.

comparison operator
A character or symbol indicating a relationship between two or more values or expressions. These operators include less than (<), less than or equal to (<=), greater than (>), greater than or equal to (>=), not equal (!=), and equal (==).

compound statement
A sequence of statements enclosed in braces ({}). Can be used to perform multiple tasks any time a single statement is expected.

constructor
A JScript function that has two special features:
  • It is invoked by the new operator.
  • It is passed the address of a newly created object through the this keyword.
Use constructors to initialize new objects.

expression
A combination of keywords, operators, variables, and literals that yield a string, number, or object. An expression can perform a calculation, manipulate characters, call a function, or test data.

intrinsic object
An object that is part of the standard JScript language. These objects are available to all scripts. The intrinsic objects in JScript are Array, Boolean, Date, Function, Global, Math, Number, Object, RegExp, Regular Expression, and String.

local time
The time on a computer, either a client or server, from where a script is executed.

locale
The set of information that corresponds to a given language and country. A locale affects the language of predefined programming terms and locale-specific settings. There are two contexts where locale information is important:
  • The code locale affects the language of terms such as keywords and defines locale-specific settings such as the decimal and list separators, date formats, and character sorting order.

  • The system locale affects the way locale-aware functionality behaves, for example, when you display numbers or convert strings to dates. You set the system locale using the Control Panel utilities provided by the operating system.

null
A value indicating that a variable contains no valid data. null is the result of:
  • An explicit assignment of null to a variable.
  • Any operation between expressions that contain null.

numeric expression
Any expression that can be evaluated as a number. Elements of the expression can include any combination of keywords, variables, literals, and operators that result in a number. In certain circumstances, strings are also converted to numbers if possible.

primitive
A data type that is part of the JScript language and manipulated by value. The data types in JScript considered to be primitive are number, Boolean, string, and function. Objects and arrays are not primitive data types.

property
A named attribute of an object. Properties define object characteristics such as size, color, and screen location, or the state of an object, such as enabled or disabled.

run-time error
An error that occurs when code is running. A run-time error results when a statement attempts an invalid operation.

scope
Defines the visibility of a variable, procedure, or object. Variables declared in functions are visible only within the function and lose their value between calls.

string comparison
A comparison of two sequences of characters. Unless specified in the function making the comparison, all string comparisons are binary. In English, binary comparisons are case-sensitive; text comparisons are not.

string expression
Any expression that evaluates to a sequence of continuguous characters. Elements of a string expression can include a function that returns a string, a string literal, a String object, or a string variable.

undefined
A special value given to variables after they are created and before a value has been assigned to them.

Universal Coordinated Time (UTC)
Universal Coordinated Time, which refers to the time as set by the World Time Standard. Previously referred to as Greenwich Mean time or GMT.

user-defined object
An object is one that is created by a user in source code.

variable
A location used for storing and manipulating values by name. As JScript is loosely typed, a single variable can hold different types of data over the course of a script.
wrapper
An object that is created to provide an object-style interface to some other type of data. The Number and Boolean objects are examples of wrapper objects.


Operator Behavior

Microsoft® JScript™
Operator Behavior 		Language Reference
Version 1

The following table describes the behavior of most Microsoft JScript operators. The columns and rows represent the different types of expressions possible on either side of an operator in JScript, and the entries in the table describe the behavior.

An E indicates a run-time error. An N indicates a numeric result, or a Boolean result in the case of logical operators.

obj | as | ns | num | bool | undef | null
obj | N | E | N | N | N | E | E
as | E | E | E | E | E | E | E
ns | N | E | N | N | N | E | E
num | N | E | N | N | N | E | E
bool | N | E | N | N | N | E | E
undef | E | E | E | E | E | E | E
null | E | E | E | E | E | E | E

obj = object, as = alphanumeric string, ns = numeric string, num = number, bool = Boolean, undef = undefined, null = null value.


concat Method (Array)

Microsoft® JScript™
concat Method (Array) 		Language Reference
Version 3

See Also Applies To

Description
Combines two arrays to create a new array.
Syntax
array1.concat(array2)

The concat method syntax has these parts:

Part | Description
array1 | Required. An Array object to concatenate with array2.
array2 | Required. An Array object to concatenate to the end of array1.

Remarks
The concat method returns an Array object containing the concatenation of array1 and array2.

If an object reference is copied from either array1 or array2 to the result, the object reference in the result still points to the same object. Changes to that object are reflected in both arrays.


concat Method (Array)

Microsoft® JScript™
concat Method (Array)
Applies To 		Language Reference

Array Object
String Object


concat Method (Array)

Microsoft® JScript™
concat Method (Array)
See Also 		Language Reference

concat Method (String)
join Method


join Method

Microsoft® JScript™
join Method 		Language Reference
Version 2

See Also Applies To

Description
Converts all elements of an array into a String object and joins them.
Syntax

arrayobj.join(separator)

The separator argument is a String object that is used to separate one element of an array from the next in the resulting String object. If omitted, the array elements are separated with an empty string.

Remarks

The join method returns a String object that contains each element converted to a string and concatenated together. An example using the join method follows:

var my_array = new Array("Jan 5", 1996, "hey", "my birthday!");
var my_string = my_array.join(", ");

After execution, my_string contains "Jan 5, 1996, hey, my birthday!"


join Method

Microsoft® JScript™
join Method
Applies To 		Language Reference

Array Object


join Method

Microsoft® JScript™
join Method
See Also 		Language Reference

Array Object Methods
String Object


length Property (Array)

Microsoft® JScript™
length Property (Array) 		Language Reference
Version 2

See Also Applies To

Description
Specifies an integer value one higher than the highest element defined in an array.
Syntax

numVar = arrayObj.length;

Remarks

As the elements in an array do not have to be contiguous, the length property is not necessarily the number of elements in the array. For example, in the following array definition, my_array.length contains 7, not 2:

var my_array = new Array( );
my_array[0] = "Test";
my_array[6] = "Another Test";

If a value smaller than its previous value is assigned to the length property, the array is truncated and any elements with array indices equal to or greater than the new value of the length property are lost.

If a value larger than its previous value is assigned to the length property, the array is expanded, and any new elements created have the value undefined.


length Property (Array)

Microsoft® JScript™
length Property (Array)
Applies To 		Language Reference

Array Object


length Property (Array)

Microsoft® JScript™
length Property (Array)
See Also 		Language Reference

length Property (Function)
length Property (String)


reverse Method

Microsoft® JScript™
reverse Method 		Language Reference
Version 2

See Also Applies To

Description

Reverses the elements of an Array object.

Syntax

arrayobj.reverse( )

Remarks

The reverse method reverses the elements of an Array object in place. It does not create a new Array object during execution.

If the array is not contiguous the reverse method creates elements in the array that fill the gaps in the array. Each of these created elements has the value undefined.


reverse Method

Microsoft® JScript™
reverse Method
Applies To 		Language Reference

Array Object


reverse Method

Microsoft® JScript™
reverse Method
See Also 		Language Reference

Array Object Methods


slice Method (Array)

Microsoft® JScript™
slice Method (Array) 		Language Reference
Version 3

See Also Applies To

Description
Returns a section of an array.
Syntax
arrayObj.slice(start, [end])

The slice method syntax has these parts:

Part | Description
arrayObj | Required. An Array object.
start | Required. The zero-based index of the beginning of the specified portion of arrayObj.
end | Optional. The zero-based index of the end of the specified portion of arrayObj.

Remarks
The slice method returns an Array object containing the specified portion of arrayObj.

The slice method copies up to, but not including, the element indicated by end. If negative, end indicates an offset from the end of arrayObj. In addition, it is not zero-based. If omitted, extraction continues to the end of arrayObj.

In the example that follows, all but the last element of myArray is copied into newArray:

newArray.slice(0, -1))
If an object reference is copied from arrayObj to the result, the object reference in the result still points to the same object. Changes to that object are reflected in both arrays.


slice Method

Microsoft® JScript™
slice Method
Applies To 		Language Reference

Array Object
String Object


slice Method

Microsoft® JScript™
slice Method
See Also 		Language Reference

slice Method (String)


sort Method

Microsoft® JScript™
sort Method 		Language Reference
Version 2

See Also Applies To

Description

Sorts the elements of an Array object.

Syntax
arrayobj.sort(sortfunction)

The sortfunction argument is the name of the function used to determine the order of the elements. If omitted, the elements are sorted in ascending, ASCII character order.

Remarks

The sort method sorts the Array object in place; no new Array object is created during execution.

If you supply a function in the sortfunction argument, it must return one of the following values:

  • A negative value if the first argument passed is less than the second argument.
  • Zero if the two arguments are equivalent.
  • A positive value if the first argument is greater than the second argument.


sort Method

Microsoft® JScript™
sort Method
Applies To 		Language Reference

Array Object


sort Method

Microsoft® JScript™
sort Method
See Also 		Language Reference

Array Object Methods


Drives Collection

Microsoft® JScript™
Drives Collection 		Language Reference
Version 3

See Also Properties Methods

Description
Read-only collection of all available drives.
Remarks
Removable-media drives need not have media inserted for them to appear in the Drives collection.

The following code illustrates how to get the Drives collection using the Drives property and iterate the collection using the Enumerator object:

function ShowDriveList()
{
    var fs, s, n, e, x;
    fs = new ActiveXObject("Scripting.FileSystemObject");
    e = new Enumerator(fs.Drives);
    s = "";
    for (; !e.atEnd(); e.moveNext())
    {
        x = e.item();
        s = s + x.DriveLetter;
        s += " - ";
        if (x.DriveType == 3)
             n = x.ShareName;
        else if (x.IsReady)
             n = x.VolumeName;
        else
             n = "[Drive not ready]";
        s +=  n + "<br>";
    }
    Response.Write(s);
}


Drives Collection

Microsoft® JScript™
Drives Collection
See Also 		Language Reference

Drive Object
Drives Property
File Object
Files Collection
Folder Object
Folders Collection


Drives Collection

Microsoft® JScript™
Drives Collection
Methods 		Language Reference

The Drives collection has no methods.


Drives Collection

Microsoft® JScript™
Drives Collection
Properties 		Language Reference

Count Property
Item Property


Files Collection

Microsoft® JScript™
Files Collection 		Language Reference
Version 3

See Also Properties Methods

Description
Collection of all File objects within a folder.
Remarks
The following code illustrates how to get a Files collection and iterate the collection using the Enumerator object and the for statement:
function ShowFolderFileList(folderspec)
{
    var fs, f, f1, fc, s;
    fs = new ActiveXObject("Scripting.FileSystemObject");
    f = fs.GetFolder(folderspec);
    fc = new Enumerator(f.files);
    s = "";
    for (; !fc.atEnd(); fc.moveNext())
    {
        s += fc.item();
        s += "<br>";
    }
    Response.Write(s);
}


Files Collection

Microsoft® JScript™
Files Collection
See Also 		Language Reference

Drive Object
Drives Collection
File Object
Folder Object
Folders Collection


Files Collection

Microsoft® JScript™
Files Collection
Methods 		Language Reference

The Files collection has no methods.


Files Collection

Microsoft® JScript™
Files Collection
Properties 		Language Reference

Count Property
Item Property


Folders Collection

Microsoft® JScript™
Folders Collection 		Language Reference
Version 3

See Also Properties Methods

Description
Collection of all Folder objects contained within a Folder object.
Remarks
The following code illustrates how to get a Folders collection and how to iterate the collection using the Enumerator object and the for statement:
function ShowFolderList(folderspec)
{
    var fs, f, f1, fc, s;
    fs = new ActiveXObject("Scripting.FileSystemObject");
    f = fs.GetFolder(folderspec);
    fc = new Enumerator(f.SubFolders);
    s = "";
    for (; !fc.atEnd(); fc.moveNext())
    {
        s += fc.item();
        s += "<br>";
    }
    Response.Write(s);
}


Folders Collection

Microsoft® JScript™
Folders Collection
See Also 		Language Reference

Drive Object
Drives Collection
File Object
Files Collection
Folder Object
SubFolders Property


Folders Collection

Microsoft® JScript™
Folders Collection
Methods 		Language Reference

AddFolders Method


Folders Collection

Microsoft® JScript™
Folders Collection
Properties 		Language Reference

Count Property
Item Property


Conditional Compilation

Microsoft® JScript™
Conditional Compilation 		Language Reference
Version 3

See Also

Description
Allows the use of new JScript language features without sacrificing compatibility with browsers that don't support the features.
Remarks
Conditional compilation is activated by using the @cc_on statement, or using an @if or @set statement outside of a comment. Some typical uses for conditional compilation are using new features in JScript, embedding debugging support into a script, and tracing code execution.

It is strongly recommended that conditional compilation code be placed in comments:

/*@cc_on @*/
/*@if (@_jscript_version == 3)
   Alert("JScript version 3");
   @else @*/
   Alert("You need a more recent script engine.");
/*@end @*/
This example uses special comment delimiters that are only used if conditional compilation is activated by the @cc_on statement. Scripting engines that do not understand conditional compilation only see the message informing of the need for a new scripting engine.


Conditional Compilation

Microsoft® JScript™
Conditional Compilation
See Also 		Language Reference

Conditional Compilation Variables
@cc_on Statement
@if Statement
@set Statement


Conditional Compilation Variables

Microsoft® JScript™
Conditional Compilation Variables 		Language Reference
Version 3

See Also

The following predefined variables are available for conditional compilation. If a variable is not true, it is not defined and behaves as NaN when accessed.

Variable | Description
@_win32 | true if running on a Win32 system.
@_win16 | true if running on a Win16 system.
@_mac | true if running on a Apple Macintosh system.
@_alpha | true if running on a DEC Alpha processor.
@_x86 | true if running on an Intel processor.
@_mc680x0 | true if running on a Motorola 680x0 processor.
@_PowerPC | true if running on a Motorola PowerPC processor.
@_jscript | Always true.
@_jscript_build | Contains the build number of the JScript scripting engine.
@_jscript_version | Contains the JScript version number in major.minor format.


Conditional Compilation Variables

Microsoft® JScript™
Conditional Compilation Variables
See Also 		Language Reference

Conditional Compilation
@cc_on Statement
@if Statement
@set Statement


getDate Method

Microsoft® JScript™
getDate Method 		Language Reference
Version 1

See Also Applies To

Description

Returns the day of the month as stored in a Date object according to local time.

Syntax
objDate.getDate()
Remarks
To get the date value according to Universal Coordinated Time (UTC), use the getUTCDate method.

The return value is an integer between 1 and 31 that represents the date stored in the Date object.


getDate Method

Microsoft® JScript™
getDate Method
Applies To 		Language Reference

Date Object


getDate Method

Microsoft® JScript™
getDate Method
See Also 		Language Reference

Date Object Methods
getUTCDate Method
setDate Method
setUTCDate Method


getDay Method

Microsoft® JScript™
getDay Method 		Language Reference
Version 1

See Also Applies To

Description

Retrieves the day of the week represented by the date stored in a Date object according to local time.
Syntax
objDate.getDay()
Remarks
To get the day according to Universal Coordinated Time (UTC), use the getUTCDay method.

The integer returned from the getDay method is an integer between 0 and 6 representing the day of the week and corresponds to a day of the week as follows:

0 = Sunday
1 = Monday
2 = Tuesday
3 = Wednesday
4 = Thursday
5 = Friday
6 = Saturday


getDay Method

Microsoft® JScript™
getDay Method
Applies To 		Language Reference

Date Object


getDay Method

Microsoft® JScript™
getDay Method
See Also 		Language Reference

Date Object Methods
getUTCDay Method


getFullYear Method

Microsoft® JScript™
getFullYear Method 		Language Reference
Version 3

See Also Applies To

Description
Returns the year stored in the Date object according to local time.
Syntax
objDate.getFullYear()
Remarks
To get the year according to Universal Coordinated Time (UTC), use the getUTCFullYear method.

The getFullYear method returns the year as an absolute number. For example, the year 1976 is returned as 1976. This avoids problems with dates occuring at the end of the 20th century.


getFullYear Method

Microsoft® JScript™
getFullYear Method
Applies To 		Language Reference

Date Object


getFullYear Method

Microsoft® JScript™
getFullYear Method
See Also 		Language Reference

Date Object Methods
getUTCFullYear Method
setFullYear Method
setUTCFullYear Method


getHours Method

Microsoft® JScript™
getHours Method 		Language Reference
Version 1

See Also Applies To

Description
Retrieves the hours stored in a Date object according to local time.
Syntax
objDate.getHours()
Remarks
To get the hours value according to Universal Coordinated Time (UTC), use the getUTCHours method.

The getHours method returns an integer between 0 and 23 indicating the number of hours since midnight. A zero occurs in two situations: the time is before 1:00:00 am, or the time was not stored in the Date object when the object was created. The only way to determine which situation you have is to also check the minutes and seconds for zero values. If they are all zeroes, it is nearly certain that the time was not stored in the Date object.


getHours Method

Microsoft® JScript™
getHours Method
Applies To 		Language Reference

Date Object


getHours Method

Microsoft® JScript™
getHours Method
See Also 		Language Reference

Date Object Methods
getUTCHours Method
setHours Method
setUTCHours Method


getMilliseconds Method

Microsoft® JScript™
getMilliseconds Method 		Language Reference
Version 3

See Also Applies To

Description
Retrieves the number of milliseconds past the second from the milliseconds value stored in a Date object according to local time.
Syntax
objDate.getMilliseconds()
Remarks
To get the number of milliseconds in Universal Coordinated Time (UTC), use the getUTCMilliseconds method.

The millisecond value returned can range from 0-999.


getMilliseconds Method

Microsoft® JScript™
getMilliseconds Method
Applies To 		Language Reference

Date Object


getMilliseconds Method

Microsoft® JScript™
getMilliseconds Method
See Also 		Language Reference

Date Object Methods
getUTCMilliseconds Method
setMilliseconds Method
setUTCMilliseconds Method


getMinutes Method

Microsoft® JScript™
getMinutes Method 		Language Reference
Version 1

See Also Applies To

Description
Retrieves the number of minutes past the hour from the minutes value stored in a Date object according to local time.
Syntax
objDate.getMinutes()
Remarks
To get the minutes value according to Universal Coordinated Time (UTC), use the getUTCMinutes method.

The getMinutes method returns an integer between 0 and 59 equal to the minutes value stored in the Date object. A zero is returned in two situations: one occurs when the time is less than one minute after the hour. The other occurs when the time was not stored in the Date object when the object was created. The only way to determine which situation you have is to also check the hours and seconds for zero values. If they are all zeroes, it is nearly certain that the time was not stored in the Date object.


getMinutes Method

Microsoft® JScript™
getMinutes Method
Applies To 		Language Reference

Date Object


getMinutes Method

Microsoft® JScript™
getMinutes Method
See Also 		Language Reference

Date Object Methods
getUTCMinutes Method
setMinutes Method
setUTCMinutes Method


getMonth Method

Microsoft® JScript™
getMonth Method 		Language Reference
Version 1

See Also Applies To

Description
Retrieves the month value of the Date object according to local time.
Syntax
objDate.getMonth()
Remarks
To get the month value according to Universal Coordinated Time (UTC), use the getUTCMonth method.

The getMonth method returns an integer between 0 and 11 indicating the month stored in the Date object. The integer returned is not the traditional number used to indicate the month. It is one less. If "Jan 5, 1996 08:47:00" is stored in a Date object, getMonth returns 0.


getMonth Method

Microsoft® JScript™
getMonth Method
Applies To 		Language Reference

Date Object


getMonth Method

Microsoft® JScript™
getMonth Method
See Also 		Language Reference

Date Object Methods
getUTCMonth Method
setMonth Method
setUTCMonth Method


getSeconds Method

Microsoft® JScript™
getSeconds Method 		Language Reference
Version 1

See Also Applies To

Description
Retrieves the number of seconds past the minute from the seconds value stored in a Date object according to local time.
Syntax
objDate.getSeconds()
Remarks
To get the seconds value according to Universal Coordinated Time (UTC), use the getUTCSeconds method.

The getSeconds method returns an integer between 0 and 59 indicating the seconds value of the indicated Date object. A zero is returned in two situations. One occurs when the time is less than one second into the current minute. The other occurs when the time was not stored in the Date object when the object was created. The only way to determine which situation you have is to also check the hours and minutes for zero values. If they are all zeroes, it is nearly certain that the time was not stored in the Date object.


getSeconds Method

Microsoft® JScript™
getSeconds Method
Applies To 		Language Reference

Date Object


getSeconds Method

Microsoft® JScript™
getSeconds Method
See Also 		Language Reference

Date Object Methods
getUTCSeconds Method
setSeconds Method
setUTCSeconds Method


getTime Method

Microsoft® JScript™
getTime Method 		Language Reference
Version 1

See Also Applies To

Description
Retrieves the time stored in a Date object.
Syntax
objDate.getTime()

Remarks
The getTime method returns an integer value representing the number of milliseconds between midnight, January 1, 1970 and the time stored in the Date object. The range of dates is approximately 285,616 years from either side of midnight, January 1, 1970. Negative numbers indicate dates prior to 1970.

When doing multiple date and time calculations, it is frequently useful to define variables equal to the number of milliseconds in a day, hour, or minute. For example:

varMinuteMilli = 1000 * 60
varHourMilli = varMinuteMilli * 60
varDayMilli = varHourMilli * 24


getTime Method

Microsoft® JScript™
getTime Method
Applies To 		Language Reference

Date Object


getTime Method

Microsoft® JScript™
getTime Method
See Also 		Language Reference

Date Object Methods
setTime Method


getTimezoneOffset Method

Microsoft® JScript™
getTimezoneOffset Method 		Language Reference
Version 1

See Also Applies To

Description

Determines the difference in minutes between the time on the host computer and Universal Coordinated Time (UTC).

Syntax
objDate.getTimezoneOffset()
Remarks
The getTimezoneOffset method returns an integer value representing the number of minutes between the time on the current machine and UTC. These values are appropriate to the computer the script is executed on. If it is called from a server script, the return value is appropriate to the server. If it is called from a client script, the return value is appropriate to the client.

This number will be positive if you are behind UTC (e.g., Pacific Daylight Time), and negative if you are ahead of UTC (e.g., Japan).

For example, suppose a server in New York City is contacted by a client in Los Angeles on December 1. getTimezoneOffset returns 480 if executed on the client, or 300 if executed on the server.


getTimezoneOffset Method

Microsoft® JScript™
getTimezoneOffset Method
Applies To 		Language Reference

Date Object


getTimezoneOffset Method

Microsoft® JScript™
getTimezoneOffset Method
See Also 		Language Reference

Date Object Methods


getUTCDate Method

Microsoft® JScript™
getUTCDate Method 		Language Reference
Version 3

See Also Applies To

Description
Returns the date of the month stored in a Date object according to Universal Coordinated Time (UTC).
Syntax
objDate.getUTCDate()
Remarks
To get the date according to local time, use the getDate method.

The return value is an integer between 1 and 31 that represents the date stored in the Date object.


getUTCDate Method

Microsoft® JScriptJScript
getUTCDate Method
Applies To 		Language Reference

Date Object


getUTCDate Method

Microsoft® JScript™
getUTCDate Method
See Also 		Language Reference

Date Object Methods
getDate Method
setDate Method
setUTCDate Method


getUTCDay Method

Microsoft® JScript™
getUTCDay Method 		Language Reference
Version 3

See Also Applies To

Description
Returns the day of the week as stored in a Date object according to Universal Coordinated Time (UTC).
Syntax
objDate.getUTCDay()
Remarks
To get the day of the week according to local time, use the getDate method.

The value returned by the getUTCDay method is an integer between 0 and 6 representing the day of the week and corresponds to a day of the week as follows:

0 = Sunday
1 = Monday
2 = Tuesday
3 = Wednesday
4 = Thursday
5 = Friday
6 = Saturday


getUTCDay Method

Microsoft® JScript™
getUTCDay Method
Applies To 		Language Reference

Date Object


getUTCDay Method

Microsoft® JScript™
getUTCDay Method
See Also 		Language Reference

Date Object Methods
getDay Method


getUTCFullYear Method

Microsoft® JScript™
getUTCFullYear Method 		Language Reference
Version 3

See Also Applies To

Description
Returns the year stored in a Date object according to Universal Coordinated Time (UTC).
Syntax
objDate.getUTCFullYear()
Remarks
To get the year according to local time, use the getFullYear method.

The getUTCFullYear method returns the year as an absolute number. This avoids problems with dates occurring at the end of the 20th century.


getUTCFullYear Method

Microsoft® JScript™
getUTCFullYear Method
Applies To 		Language Reference

Date Object


getUTCFullYear Method

Microsoft® JScript™
getUTCFullYear Method
See Also 		Language Reference

Date Object Methods
getFullYear Method
setFullYear Method
setUTCFullYear Method


getUTCHours Method

Microsoft® JScript™
getUTCHours Method 		Language Reference
Version 3

See Also Applies To

Description
Returns the hours stored in a Date object according to Universal Coordinated Time (UTC).
Syntax
objDate.getUTCHours()
Remarks
To get the number of hours elapsed since midnight using local time, use the getHours method.

The getUTCHours method returns an integer between 0 and 23 indicating the number of hours since midnight. A zero occurs in two situations: the time is before 1:00:00 A.M., or a time was not stored in the Date object when the object was created. The only way to determine which situation you have is to also check the minutes and seconds for zero values. If they are all zeroes, it is nearly certain that the time was not stored in the Date object.


getUTCHours Method

Microsoft® JScript™
getUTCHours Method
Applies To 		Language Reference

Date Object


getUTCHours Method

Microsoft® JScript™
getUTCHours Method
See Also 		Language Reference

Date Object Methods
getHours Method
setHours Method
setUTCHours Method


getUTCMilliseconds Method

Microsoft® JScript™
getUTCMilliseconds Method 		Language Reference
Version 3

See Also Applies To

Description
Retrieves the number of milliseconds past the second from the milliseconds value stored in a Date object according to Universal Coordinated Time (UTC).
Syntax
objDate.getUTCMilliseconds()
Remarks
To get the number of milliseconds in local time, use the getMilliseconds method.

The millisecond value returned can range from 0-999.


getUTCMilliseconds Method

Microsoft® JScript™
getUTCMilliseconds Method
Applies To 		Language Reference

Date Object


getUTCMilliseconds Method

Microsoft® JScript™
getUTCMilliseconds Method
See Also 		Language Reference

Date Object Methods
getMilliseconds Method
setMilliseconds Method
setUTCMilliseconds Method


getUTCMinutes Method

Microsoft® JScript™
getUTCMinutes Method 		Language Reference
Version 3

See Also Applies To

Description
Retrieves the number of minutes past the hour from the minutes value stored in a Date object according to Universal Coordinated Time (UTC).
Syntax
objDate.getUTCMinutes()
Remarks
To get the number of minutes stored using local time, use the getMinutes method.

The getUTCMinutes method returns an integer between 0 and 59 equal to the number of minutes stored in the Date object. A zero occurs in two situations: the time is less than one minute after the hour, or a time was not stored in the Date object when the object was created. The only way to determine which situation you have is to also check the hours and seconds for zero values. If they are all zeroes, it is nearly certain that the time was not stored in the Date object.


getUTCMinutes Method

Microsoft® JScript™
getUTCMinutes Method
Applies To 		Language Reference

Date Object


getUTCMinutes Method

Microsoft® JScript™
getUTCMinutes Method
See Also 		Language Reference

Date Object Methods
getMinutes Method
setMinutes Method
setUTCMinutes Method


getUTCMonth Method

Microsoft® JScript™
getUTCMonth Method 		Language Reference
Version 3

See Also Applies To

Description
Retrieves the month value stored in a Date object according to Universal Coordinated Time (UTC).
Syntax
objDate.getUTCMonth()
Remarks
To get the month in local time, use the getMonth method.

The getUTCMonth method returns an integer between 0 and 11 indicating the month stored in the Date object. The integer returned is not the traditional number used to indicate the month. It is one less. If "Jan 5, 1996 08:47:00.0" is stored in a Date object, getUTCMonth returns 0.


getUTCMonth Method

Microsoft® JScript™
getUTCMonth Method
Applies To 		Language Reference

Date Object


getUTCMonth Method

Microsoft® JScript™
getUTCMonth Method
See Also 		Language Reference

Date Object Methods
getMonth Method
setMonth Method
setUTCMonth Method


getUTCSeconds Method

Microsoft® JScript™
getUTCSeconds Method 		Language Reference
Version 3

See Also Applies To

Description
Retrieves the number of seconds past the minute from the seconds value stored in a Date object according to Universal Coordinated Time (UTC).
Syntax
objDate.getUTCSeconds()
Remarks
To get the number of seconds in local time, use the getSeconds method.

The getUTCSeconds method returns an integer between 0 and 59 indicating the seconds value of the indicated Date object. A zero occurs in two situations: the time is less than one second into the current minute, or a time was not stored in the Date object when the object was created. The only way to determine which situation you have is to also check the minutes and hours for zero values. If they are all zeroes, it is nearly certain that the time was not stored in the Date object.


getUTCSeconds Method

Microsoft® JScript™
getUTCSeconds Method
Applies To 		Language Reference

Date Object


getUTCSeconds Method

Microsoft® JScript™
getUTCSeconds Method
See Also 		Language Reference

Date Object Methods
getSeconds Method
setSeconds Method
setUTCSeconds Method


getVarDate Method

Microsoft® JScript™
getVarDate Method 		Language Reference
Version 3

See Also Applies To

Description
Returns the VT_DATE value stored in the Date object.
Syntax
dateobj.getVarDate( )

The dateobj argument is any Date object.

Remarks
The getVarDate method is used when interacting with ActiveX or other objects that accept and return date values in VT_DATE format.


getVarDate Method

Microsoft® JScript™
getVarDate Method
Applies To 		Language Reference

Date Object


getVarDate Method

Microsoft® JScript™
getVarDate Method
See Also 		Language Reference

getDate Method
parse Method


getYear Method

Microsoft® JScript™
getYear Method 		Language Reference
Version 1

See Also Applies To

Description

Retrieves the year stored in the specified Date object.

Syntax

objDate.getYear()
Remarks
This method is obsolete, and is provided for backwards compatibility only. Use the getFullYear method instead.

The year is an integer value and is returned as the difference between the stored year and 1900. For example, 1996 is returned as 96, and 2025 is returned as 125.


getYear Method

Microsoft® JScript™
getYear Method
Applies To 		Language Reference

Date Object


getYear Method

Microsoft® JScript™
getYear Method
See Also 		Language Reference

Date Object Methods
getFullYear Method
getUTCFullYear Method
setFullYear Method
setUTCFullYear Method
setYear Method


parse Method

Microsoft® JScript™
parse Method 		Language Reference
Version 1

See Also Applies To

Description

Parses a string containing a date, and returns the number of milliseconds between that date and midnight, January 1, 1970.

Syntax
Date.parse(dateVal)

The dateVal argument is either a string containing a date in a format such as "Jan 5, 1996 08:47:00" or a VT_DATE value retrieved from an ActiveX or other object.

Remarks

The parse method returns an integer value representing the number of milliseconds between midnight, January 1, 1970 and the date supplied in dateVal.

The parse method is a static method of the Date object. Because it is a static method, it is invoked as shown in the following code rather than invoked as a method of a created Date object.

var datestring = "November 1, 1997 10:15 AM";
Date.parse(datestring)
The following rules govern what the parse method can successfully parse:
  • Short dates can use either a "/" or "-" date separator, but must follow the month/day/year format, for example "7/20/96".
  • Long dates of the form "July 10 1995" can be given with the year, month, and day in any order, and the year in 2- or 4-digit form. If you use the 2-digit form, the year must be greater than or equal to 70.
  • Any text inside parentheses is treated as a comment. These parentheses may be nested.
  • Both commas and spaces are treated as delimiters. Multiple delimiters are permitted.
  • Month and day names must have two or more characters. Two character names that are not unique are resolved as the last match. For example, "Ju" is resolved as July, not June.
  • The stated day of the week is ignored if it is incorrect given the remainder of the supplied date. For example, "Tuesday November 9 1996" is accepted and parsed even though that date actually falls on a Friday. The resulting Date object contains "Friday November 9 1996".
  • JScript handles all standard time zones, as well as Universal Coordinated Time (UTC) and Greenwich Mean Time (GMT).
  • Hours, minutes, and seconds are separated by colons, although all need not be specified. "10:", "10:11", and "10:11:12" are all valid.
  • If the 24-hour clock is used, it is an error to specify "PM" for times later than 12 noon. For example, "23:15 PM" is an error.
  • A string containing an invalid date is an error. For example, a string containing two years or two months is an error.


parse Method

Microsoft® JScript™
parse Method
Applies To 		Language Reference

Date Object


parse Method

Microsoft® JScript™
parse Method
See Also 		Language Reference

Date Object Methods
UTC Method


setDate Method

Microsoft® JScript™
setDate Method 		Language Reference
Version 1

See Also Applies To

Description

Sets the numeric date of the Date object according to local time.
Syntax
objDate.setDate(numDate)

The numDate argument is a numeric value equal to the numeric date.

Remarks
To set the date value according to Universal Coordinated Time (UTC), use the setUTCDate method.

If the value of numDate is greater than the number of days in the month stored in the Date object or is a negative number, the date is set to a date equal to numDate minus the number of days in the stored month. For example, if the stored date is January 5, 1996, and setDate(32) is called, the date changes to February 1, 1996. Negative numbers have a similar behavior.


setDate Method

Microsoft® JScript™
setDate Method
Applies To 		Language Reference

Date Object


setDate Method

Microsoft® JScript™
setDate Method
See Also 		Language Reference

Date Object Methods
getDate Method
getUTCDate Method
setUTCDate Method


setFullYear Method

Microsoft® JScript™
setFullYear Method 		Language Reference
Version 3

See Also Applies To

Description
Sets the year value in the Date object according to local time.
Syntax
objDate.setFullYear(numYear[, numMonth[, numDate]])

The setFullYear method syntax has these parts:

Part | Description
numYear | Required. A numeric value equal to the year.
numMonth | Optional. A numeric value equal to the month. Must be supplied if numDate is supplied.
numDate | Optional. A numeric value equal to the date.

Remarks

All set methods taking optional arguments use the value returned from corresponding get methods, if you do not specify an optional argument. For example, if the numMonth argument is optional, but not specified, JScript uses the value returned from the getMonth method.

In addition, if the value of an argument is greater that its range or is a negative number, other stored values are modified accordingly.

To set the year according to Universal Coordinated Time (UTC), use the setUTCFullYear method.

The range of years supported in the date object is approximately 285,616 years from either side of 1970.


setFullYear Method

Microsoft® JScript™
setFullYear Method
Applies To 		Language Reference

Date Object


setFullYear Method

Microsoft® JScript™
setFullYear Method
See Also 		Language Reference

Date Object Methods
getFullYear Method
getUTCFullYear Method
setUTCFullYear Method


setHours Method

Microsoft® JScript™
setHours Method 		Language Reference
Version 1

See Also Applies To

Description

Modifies the hours stored in the Date object according to local time.

Syntax
objDate.setHours(numHours[, numMin[, numSec[, numMilli]]])

The setHours method syntax has these parts:

Part | Description
numHours | Required. A numeric value equal to the hours value.
numMin | Optional. A numeric value equal to the minutes value. Must be supplied if either of the following arguments are used.
numSec | Optional. A numeric value equal to the seconds value. Must be supplied if the following argument is used.
numMilli | Optional. A numeric value equal to the milliseconds value.

Remarks

All set methods taking optional arguments use the value returned from corresponding get methods, if you do not specify an optional argument. For example, if the numMonth argument is optional, but not specified, JScript uses the value returned from the getMonth method.

To set the hours value according to Universal Coordinated Time (UTC), use the setUTCHours method.

If the value of an argument is greater than its range or is a negative number, other stored values are modified accordingly. For example, if the stored date is "Jan 5, 1996 00:00:00", and setHours(30) is called, the date is changed to "Jan 6, 1996 06:00:00." Negative numbers have a similar behavior.


setHours Method

Microsoft® JScript™
setHours Method
Applies To 		Language Reference

Date Object


setHours Method

Microsoft® JScript™
setHours Method
See Also 		Language Reference

Date Object Methods
getHours Method
getUTCHours Method
setUTCHours Method


setMilliseconds Method

Microsoft® JScript™
setMilliseconds Method 		Language Reference
Version 3

See Also Applies To

Description

Modifies the milliseconds value stored in the Date object according to local time.

Syntax
objDate.setMilliseconds(numMilli)

The numMilli argument is a numeric value equal to the millisecond value.

Remarks

All set methods taking optional arguments use the value returned from corresponding get methods, if you do not specify an optional argument. For example, if the numMonth argument is optional, but not specified, JScript uses the value returned from the getMonth method.

To set the milliseconds value according to Universal Coordinated Time (UTC), use the setUTCMilliseconds method.

If the value of numMilli is greater than 999 or is a negative number, the stored number of seconds (and minutes, hours, and so forth if necessary) is incremented an appropriate amount.


getMilliseconds Method

Microsoft® JScript™
setMilliseconds Method
Applies To 		Language Reference

Date Object


setMilliseconds Method

Microsoft® JScript™
setMilliseconds Method
See Also 		Language Reference

Date Object Methods
getMilliseconds Method
getUTCMilliseconds Method
setUTCMilliseconds Method


setMinutes Method

Microsoft® JScript™
setMinutes Method 		Language Reference
Version 1

See Also Applies To

Description

Modifies the minutes stored in the Date object according to local time.

Syntax
objDate.setMinutes(numMinutes[, numSeconds[, numMilli]])

The setMinutes method syntax has these parts:

Part | Description
numMinutes | Required. A numeric value equal to the minutes value.
numSeconds | Optional. A numeric value equal to the seconds value. Must be supplied if the numMilli argument is used.
numMilli | Optional. A numeric value equal to the milliseconds value.

Remarks

All set methods taking optional arguments use the value returned from corresponding get methods, if you do not specify an optional argument. For example, if the numMonth argument is optional, but not specified, JScript uses the value returned from the getMonth method.

To set the minutes value according to Universal Coordinated Time (UTC), use the setUTCMinutes method.

If the value of an argument is greater than its range or is a negative number, other stored values are modified accordingly. For example, if the stored date is "Jan 5, 1996 00:00:00" and setMinutes(90) is called, the date is changed to "Jan 5, 1996 01:30:00." Negative numbers have a similar behavior.


setMinutes Method

Microsoft® JScript™
setMinutes Method
Applies To 		Language Reference

Date Object


setMinutes Method

Microsoft® JScript™
setMinutes Method
See Also 		Language Reference

Date Object Methods
getMinutes Method
getUTCMinutes Method
setUTCMinutes Method


setMonth Method

Microsoft® JScript™
setMonth Method 		Language Reference
Version 1

See Also Applies To

Description

Modifies the month stored in the Date object according to local time.

Syntax
objDate.setMonth(numMonth[, dateVal])

The setMonth method syntax has these parts:

Part | Description
numMonth | Required. A numeric value equal to the month.
dateVal | Optional. A numeric value representing the date. If not supplied, the value from a call to the getDate method is used.

Remarks
To set the month value according to Universal Coordinated Time (UTC), use the setUTCMonth method.

If the value of numMonth is greater than 11 (January is month 0) or is a negative number, the stored year is modified accordingly. For example, if the stored date is "Jan 5, 1996" and setMonth(14) is called, the date is changed to "Mar 5, 1997."


setMonth Method

Microsoft® JScript™
setMonth Method
Applies To 		Language Reference

Date Object


setMonth Method

Microsoft® JScript™
setMonth Method
See Also 		Language Reference

Date Object Methods
getMonth Method
getUTCMonth Method
setUTCMonth Method


setSeconds Method

Microsoft® JScript™
setSeconds Method 		Language Reference
Version 1

See Also Applies To

Description

Modifies the seconds value stored in the Date object according to local time.

Syntax
objDate.setSeconds(numSeconds[, numMilli])

The setSeconds method syntax has these parts:

Part | Description
numSeconds | Required. A numeric value equal to the seconds value.
numMilli | Optional. A numeric value equal to the milliseconds value.

Remarks

All set methods taking optional arguments use the value returned from corresponding get methods, if you do not specify an optional argument. For example, if the numMonth argument is optional, but not specified, JScript uses the value returned from the getMonth method.

To set the seconds value according to Universal Coordinated Time (UTC), use the setUTCSeconds method.

If the value of an argument is greater than its range or is a negative number, other stored values are modified accordingly. For example, if the stored date is "Jan 5, 1996 00:00:00" and setSeconds(150) is called, the date is changed to "Jan 5, 1996 00:02:30."


setSeconds Method

Microsoft® JScript™
setSeconds Method
Applies To 		Language Reference

Date Object


setSeconds Method

Microsoft® JScript™
setSeconds Method
See Also 		Language Reference

Date Object Methods
getSeconds Method
getUTCSeconds Method
setUTCSeconds Method


setTime Method

Microsoft® JScript™
setTime Method 		Language Reference
Version 1

See Also Applies To

Description

Sets the date and time value directly in the Date object.

Syntax
objDate.setTime(milliseconds)

The milliseconds argument is an integer value representing the number of elapsed seconds since midnight, January 1, 1970 GMT.

Remarks
If milliseconds is negative, it indicates a date before 1970. The range of available dates is approximately 285,616 years from either side of 1970.

Setting the date and time with the setTime method is independent of the time zone.


setTime Method

Microsoft® JScript™
setTime Method
Applies To 		Language Reference

Date Object


setTime Method

Microsoft® JScript™
setTime Method
See Also 		Language Reference

Date Object Methods
getTime Method


setUTCDate Method

Microsoft® JScript™
setUTCDate Method 		Language Reference
Version 3

See Also Applies To

Description
Sets the numeric date of the Date object in Universal Coordinated Time (UTC).
Syntax
objDate.setUTCDate(numDate)

The numDate argument is a numeric value equal to the numeric date.

Remarks
To set the date according to local time, use the setDate method.

If the value of numDate is greater than the number of days in the month stored in the Date object or is a negative number, the date is set to a date equal to numDate minus the number of days in the stored month. For example if the stored date is January 5, 1996, and setUTCDate(32) is called, the date changes to February 1, 1996. Negative numbers have a similar behavior.


setUTCDate Method

Microsoft® JScript™
setUTCDate Method
Applies To 		Language Reference

Date Object


setUTCDate Method

Microsoft® JScript™
setUTCDate Method
See Also 		Language Reference

Date Object Methods
getDate Method
getUTCDate Method
setDate Method


setUTCFullYear Method

Microsoft® JScript™
setUTCFullYear Method 		Language Reference
Version 3

See Also Applies To

Description
Sets the year value in the Date object according to Universal Coordinated Time (UTC).
Syntax
objDate.setUTCFullYear(numYear[, numMonth[, numDate]])

The setUTCFullYear method syntax has these parts:

Part | Description
numYear | Required. A numeric value equal to the year.
numMonth | Optional. A numeric value equal to the month. Must be supplied if numDate is supplied.
numDate | Optional. A numeric value equal to the date.

Remarks

All set methods taking optional arguments use the value returned from corresponding get methods, if you do not specify an optional argument. For example, if the numMonth argument is optional, but not specified, JScript uses the value returned from the getMonth method.

In addition, if the value of an argument is greater that its range or is a negative number, other stored values are modified accordingly.

To set the year according to local time, use the setFullYear method.

The range of years supported in the Date object is approximately 285,616 years from either side of 1970.


setUTCFullYear Method

Microsoft® JScript™
setUTCFullYear Method
Applies To 		Language Reference

Date Object


setUTCFullYear Method

Microsoft® JScript™
setUTCFullYear Method
See Also 		Language Reference

Date Object Methods
getFullYear Method
getUTCFullYear Method
setFullYear Method


setUTCHours Method

Microsoft® JScript™
setUTCHours Method 		Language Reference
Version 3

See Also Applies To

Description
Modifies the hours stored in the Date object according to Universal Coordinated Time (UTC).
Syntax
objDate.setUTCHours(numHours[, numMin[, numSec[, numMilli]]])

The setUTCHours method syntax has these parts:

Part | Description
numHours | Required. A numeric value equal to the hours value.
numMin | Optional. A numeric value equal to the minutes value. Must be supplied if either numSec or numMilli are used.
numSec | Optional. A numeric value equal to the seconds value. Must be supplied if numMilli argument is used.
numMilli | Optional. A numeric value equal to the milliseconds value.

Remarks

All set methods taking optional arguments use the value returned from corresponding get methods, if you do not specify an optional argument. For example, if the numMonth argument is optional, but not specified, JScript uses the value returned from the getMonth method.

To set the hours value according to local time, use the setHours method.

If the value of an argument is greater than its range or is a negative number, other stored values are modified accordingly. For example, if the stored date is "Jan 5, 1996 00:00:00.00", and setUTCHours(30) is called, the date is changed to "Jan 6, 1996 06:00:00.00."


setUTCHours Method

Microsoft® JScript™
setUTCHours Method
Applies To 		Language Reference

Date Object


setUTCHours Method

Microsoft® JScript™
setUTCHours Method
See Also 		Language Reference

Date Object Methods
getHours Method
getUTCHours Method
setHours Method


setUTCMilliseconds Method

Microsoft® JScript™
setUTCMilliseconds Method 		Language Reference
Version 3

See Also Applies To

Description
Modifies the milliseconds value stored in the Date object according to Universal Coordinated Time (UTC).
Syntax
objDate.setUTCMilliseconds(numMilli)

The numMilli argument is a numeric value equal to the milliseconds value.

Remarks

To set the milliseconds according to local time, use the setMilliseconds method.

If the value of numMilli is greater than 999 or is a negative number, the stored number of seconds (and minutes, hours, and so forth if necessary) is incremented an appropriate amount.


setUTCMilliseconds Method

Microsoft® JScript™
setUTCMilliseconds Method
Applies To 		Language Reference

Date Object


setUTCMilliseconds Method

Microsoft® JScript™
setUTCMilliseconds Method
See Also 		Language Reference

Date Object Methods
getMilliseconds Method
getUTCMilliseconds Method
setMilliseconds Method


setUTCMinutes Method

Microsoft® JScript™
setUTCMinutes Method 		Language Reference
Version 3

See Also Applies To

Description
Modifies the minutes value of the Date object according to Universal Coordinated Time (UTC).
Syntax
objDate.setUTCMinutes(numMinutes[, numSeconds[, numMilli]])

The setUTCMinutes method syntax has these parts:

Part | Description
numMinutes | Required. A numeric value equal to the minutes value.
numSeconds | Optional. A numeric value equal to the seconds value. Must be supplied if numMilli is used.
numMilli | Optional. A numeric value equal to the milliseconds value.

Remarks

All set methods taking optional arguments use the value returned from corresponding get methods, if you do not specify an optional argument. For example, if the numMonth argument is optional, but not specified, JScript uses the value returned from the getMonth method.

To modify the minutes value according to local time, use the setMinutes method.

If the value of an argument is greater than its range or is a negative number, other stored values are modified accordingly. For example, if the stored date is "Jan 5, 1996 00:00:00.00", and setUTCMinutes(70) is called, the date is changed to "Jan 5, 1996 01:10:00.00."


setUTCMinutes Method

Microsoft® JScript™
setUTCMinutes Method
Applies To 		Language Reference

Date Object


setUTCMinutes Method

Microsoft® JScript™
setUTCMinutes Method
See Also 		Language Reference

Date Object Methods
getMinutes Method
getUTCMinutes Method
setMinutes Method


setUTCMonth Method

Microsoft® JScript™
setUTCMonth Method 		Language Reference
Version 3

See Also Applies To

Description
Modifies the month stored in the Date object according to Universal Coordinated Time (UTC).
Syntax
objDate.setUTCMonth(numMonth[, dateVal])

The setUTCMonth method syntax has these parts:

Part | Description
numMonth | Required. A numeric value equal to the month.
dateVal | Optional. A numeric value representing the date. If not supplied, the value from a call to the getUTCDate method is used.

Remarks
To set the month value according to local time, use the setMonth method.

If the value of numMonth is greater than 11 (January is month 0) or is a negative number, the stored year is incremented or decremented appropriately. For example, if the stored date is "Jan 5, 1996 00:00:00.00", and setUTCMonth(14) is called, the date is changed to "Mar 5, 1997 00:00:00.00."


setUTCMonth Method

Microsoft® JScript™
setUTCMonth Method
Applies To 		Language Reference

Date Object


setUTCMonth Method

Microsoft® JScript™
setUTCMonth Method
See Also 		Language Reference

Date Object Methods
getMonth Method
getUTCMonth Method
setMonth Method


setUTCSeconds Method

Microsoft® JScript™
setUTCSeconds Method 		Language Reference
Version 3

See Also Applies To

Description
Modifies the seconds value stored in the Date object according to Universal Coordinated Time (UTC).
Syntax
objDate.setUTCSeconds(numSeconds[, numMilli])

The setUTCSeconds method syntax has these parts:

Part | Description
numSeconds | Required. A numeric value equal to the seconds value.
numMilli | Optional. A numeric value equal to the milliseconds value.

Remarks

All set methods taking optional arguments use the value returned from corresponding get methods, if you do not specify an optional argument. For example, if the numMonth argument is optional, but not specified, JScript uses the value returned from the getMonth method.

To set the seconds value according to local time, use the setSeconds method.

If the value of an argument is greater than its range or is a negative number, other stored values are modified accordingly. For example, if the stored date is "Jan 5, 1996 00:00:00.00" and setSeconds(150) is called, the date is changed to "Jan 5, 1996 00:02:30.00."


setUTCSeconds Method

Microsoft® JScript™
setUTCSeconds Method
Applies To 		Language Reference

Date Object


setUTCSeconds Method

Microsoft® JScript™
setUTCSeconds Method
See Also 		Language Reference

Date Object Methods
getSeconds Method
getUTCSeconds Method
setSeconds Method


setYear Method

Microsoft® JScript™
setYear Method 		Language Reference
Version 1

See Also Applies To

Description

Sets the year value in the Date object.

Syntax
objDate.setYear(numYear)

The numYear argument is a numeric value equal to the year minus 1900.

Remarks
This method is obsolete, and is maintained for backwards compatibility only. Use the setFullYear method instead.

To set the year of a Date object to 1997, call setYear(97). To set the year to 110, call setYear(110). Finally, to set the year to a year in the range 0-99, use the setFullYear method.


setYear Method

Microsoft® JScript™
setYear Method
Applies To 		Language Reference

Date Object


setYear Method

Microsoft® JScript™
setYear Method
See Also 		Language Reference

Date Object Methods
getFullYear Method
getUTCFullYear Method
getYear Method
setFullYear Method
setUTCFullYear Method


toGMTString Method

Microsoft® JScript™
toGMTString Method 		Language Reference
Version 1

See Also Applies To

Description

Converts the date to a string using GMT convention.

Syntax
objDate.toGMTString()
Remarks

The toGMTString method is obsolete, and is provided for backwards compatibility only. It is recommended that you use the toUTCString method instead

The toGMTString method returns a String object that contains the date formatted using GMT convention. The format of the return value is as follows: "05 Jan 1996 00:00:00 GMT."


toGMTString Method

Microsoft® JScript™
toGMTString Method
Applies To 		Language Reference

Date Object


toGMTString Method

Microsoft® JScript™
toGMTString Method
See Also 		Language Reference

Date Object Methods
toUTCString Method


toLocaleString Method

Microsoft® JScript™
toLocaleString Method 		Language Reference
Version 1

See Also Applies To

Description

Converts the date to a string using the current locale.

Syntax
dateObj.toLocaleString( )
Remarks

The toLocaleString method returns a String object that contains the date written in the current locale's default format. The format of the return value depends on the current locale. For example, in the United States, toLocaleString may return "01/05/96 00:00:00" for January 5, but in Europe, it may return "05/01/96 00:00:00" for the same date, as European convention puts the day before the month.


toLocaleString Method

Microsoft® JScript™
toLocaleString Method
Applies To 		Language Reference

Date Object


toLocaleString Method

Microsoft® JScript™
toLocaleString Method
See Also 		Language Reference

Date Object Methods


toUTCString Method

Microsoft® JScript™
toUTCString Method 		Language Reference
Version 3

See Also Applies To

Description

Converts the date to a string in Universal Coordinated Time (UTC).

Syntax
objDate.toUTCString()
Remarks

The toUTCString method returns a String object that contains the date formatted using UTC convention in a convenient, easily readable form.


toUTCString Method

Microsoft® JScript™
toUTCString Method
Applies To 		Language Reference

Date Object


toUTCString Method

Microsoft® JScript™
toUTCString Method
See Also 		Language Reference

Date Object Methods
toGMTString Method


UTC Method

Microsoft® JScript™
UTC Method 		Language Reference
Version 1

See Also Applies To

Description

Computes the number of milliseconds between midnight, January 1, 1970 Universal Coordinated Time (UTC) (or GMT) and the supplied date.

Syntax
Date.UTC(year, month, day[, hours[, minutes[, seconds[,ms]]]])

The UTC method syntax has these parts:

Part | Description
year | Required. The full year designation is required for cross-century date accuracy. If year is between 0 and 99 is used, then year is assumed to be 1900 + year.
month | Required. The month as an integer between 0 and 11 (January to December).
date | Required. The date as an integer between 1 and 31.
hours | Optional. Must be supplied if minutes is supplied. An integer from 0 to 23 (midnight to 11pm) that specifies the hour.
minutes | Optional. Must be supplied if seconds is supplied. An integer from 0 to 59 that specifies the minutes.
seconds | Optional. Must be supplied if milliseconds is supplied. An integer from 0 to 59 that specifies the seconds.
ms | Optional. An integer from 0 to 999 that specifies the milliseconds.

Remarks

The UTC method returns the number of milliseconds between midnight, January 1, 1970 UTC and the supplied date. This return value can be used in the setTime method and in the Date object constructor. If the value of an argument is greater than its range or is a negative number, other stored values are modified accordingly. For example, if you specify 150 seconds, JScript redefines that number as two minutes and 30 seconds.

The difference between the UTC method and the Date object constructor that accepts a date is that the UTC method assumes UTC, and the Date object constructor assumes local time.

The UTC method is a static method. Therefore, a Date object does not have to be created before it can be used. The UTC method is invoked as follows:

var datestring = "November 1, 1997 10:15 AM";
Date.UTC(datestring)
Note If year is between 0 and 99, use 1900 + year for the year.


UTC Method

Microsoft® JScript™
UTC Method
Applies To 		Language Reference

Date Object


UTC Method

Microsoft® JScript™
UTC Method
See Also 		Language Reference

Date Object Methods
setTime Method


Add Method

Microsoft® JScript™
Add Method 		Language Reference
Version 2

See Also Applies To

Description
Adds a key and item pair to a Dictionary object.
Syntax
object.Add (key, item)

The Add method has the following parts:

Part | Description
object | Required. Always the name of a Dictionary object.
key | Required. The key associated with the item being added.
item | Required. The item associated with the key being added.

Remarks
An error occurs if the key already exists.


Add Method

Microsoft® JScript™
Add Method
Applies To 		Language Reference

Dictionary Object


Add Method

Microsoft® JScript™
Add Method
See Also 		Language Reference

AddFolders Method
Exists Method
Items Method
Keys Method
Remove Method
RemoveAll Method


CompareMode Property

Microsoft® JScript™
CompareMode Property 		Language Reference
Version 2

See Also Applies To

Description
Sets and returns the comparison mode for comparing string keys in a Dictionary object.
Syntax
object.CompareMode[ = compare]

The CompareMode property has the following parts:

Part | Description
object | Required. Always the name of a Dictionary object.
compare | Optional. If provided, compare is a value representing the comparison mode. Acceptable values are 0 (Binary), 1 (Text), 2 (Database). Values greater than 2 can be used to refer to comparisons using specific Locale IDs (LCID).

Remarks
An error occurs if you try to change the comparison mode of a Dictionary object that already contains data.


CompareMode Property

Microsoft® JScript™
CompareMode Property
Applies To 		Language Reference

Dictionary Object


CompareMode Property

Microsoft® JScript™
CompareMode Property
See Also 		Language Reference

Key Property


Count Property

Microsoft® JScript™
Count Property 		Language Reference
Version 2

See Also Applies To

Description
Returns the number of items in a collection or Dictionary object. Read-only.
Syntax
object.Count

The object is always the name of one of the items in the Applies To list.

Remarks
The following code illustrates use of the Count property:
var a, d, i, s;                 // Create some variables.
d = new ActiveXObject("Scripting.Dictionary");
d.Add ("a", "Athens");          // Add some keys and items
d.Add ("b", "Belgrade");
d.Add ("c", "Cairo");
a = (new VBArray(d.Keys()));    // Get the keys.
s = "";
for (i = 0; i < d.Count; i++)   //Iterate the dictionary.
{
   s += a.getItem(i) + " - " + d(a.getItem(i)) + "<br>";
}
document.write(s);              // Print item.


Count Property

Microsoft® JScript™
Count Property
Applies To 		Language Reference

Dictionary Object
Drives Collection
Files Collection
Folders Collection


Count Property

Microsoft® JScript™
Count Property
See Also 		Language Reference

CompareMode Property
Item Property
Key Property


Exists Method

Microsoft® JScript™
Exists Method 		Language Reference
Version 2

See Also Applies To

Description
Returns true if a specified key exists in the Dictionary object, false if it does not.

Syntax
object.Exists(key)

The Exists method syntax has these parts:

Part | Description
object | Required. Always the name of a Dictionary object.
key | Required. Key value being searched for in the Dictionary object.


Exists Method

Microsoft® JScript™
Exists Method
Applies To 		Language Reference

Dictionary Object


Exists Method

Microsoft® JScript™
Exists Method
See Also 		Language Reference

Items Method
Keys Method


Item Property

Microsoft® JScript™
Item Property 		Language Reference
Version 2

See Also Applies To

Description
Sets or returns an item for a specified key in a Dictionary object. For collections, returns an item based on the specified key. Read/write.
Syntax
object.Item(key)[ = newitem]

The Item property has the following parts:

Part | Description
object | Required. Always the name of a collection or Dictionary object.
key | Required. Key associated with the item being retrieved or added.
newitem | Optional. Used for Dictionary object only; no application for collections. If provided, newitem is the new value associated with the specified key.

Remarks
If key is not found when changing an item, a new key is created with the specified newitem. If key is not found when attempting to return an existing item, a new key is created and its corresponding item is left empty.


Item Property

Microsoft® JScript™
Item Property
Applies To 		Language Reference

Dictionary Object
Drives Collection
Files Collection
Folders Collection


Item Property

Microsoft® JScript™
Item Property
See Also 		Language Reference

CompareMode Property
Count Property
Key Property


Items Method

Microsoft® JScript™
Items Method 		Language Reference
Version 2

See Also Applies To

Description
Returns an array containing all the items in a Dictionary object.
Syntax
object.Items( )

The object is always the name of a Dictionary object.

Remarks
The following code illustrates use of the Items method:
var a, d, i, s;              // Create some variables.
d = new ActiveXObject("Scripting.Dictionary");
d.Add ("a", "Athens");       // Add some keys and items
d.Add ("b", "Belgrade");
d.Add ("c", "Cairo");
a = (new VBArray(d.Items())).toArray();    // Get the items.
s = "";
for (i in a)               //Iterate the dictionary.
{
   s += a[i] + "<br>";
}
document.write(s);           // Print item.


Items Method

Microsoft® JScript™
Items Method
Applies To 		Language Reference

Dictionary Object


Items Method

Microsoft® JScript™
Items Method
See Also 		Language Reference

Exists Method
Keys Method


Key Property

Microsoft® JScript™
Key Property 		Language Reference
Version 2

See Also Applies To

Description
Sets a key in a Dictionary object.

Syntax
object.Key(key) = newkey

The Key property has the following parts:

Part | Description
object | Required. Always the name of a Dictionary object.
key | Required. Key value being changed.
newkey | Required. New value that replaces the specified key.

Remarks
If key is not found when changing a key, a new key is created and its associated item is left empty.


Key Property

Microsoft® JScript™
Key Property
Applies To 		Language Reference

Dictionary Object


Key Property

Microsoft® JScript™
Key Property
See Also 		Language Reference

CompareMode Property
Count Property
Item Property


Keys Method

Microsoft® JScript™
Keys Method 		Language Reference
Version 2

See Also Applies To

Description
Returns an array containing all existing keys in a Dictionary object.
Syntax
object.Keys( )

The object is always the name of a Dictionary object.

Remarks
The following code illustrates use of the Keys method:
var a, d, i, s;              // Create some variables.
d = new ActiveXObject("Scripting.Dictionary");
d.Add ("a", "Athens");       // Add some keys and items
d.Add ("b", "Belgrade");
d.Add ("c", "Cairo");
a = (new VBArray(d.Keys())).toArray();    // Get the keys.
s = "";
for (i in a)                 //Iterate the dictionary.
{
   s += a[i] + " - " + d(a[i]) + "<br>";
}
document.write(s);           // Print item.


Keys Method

Microsoft® JScript™
Keys Method
Applies To 		Language Reference

Dictionary Object


Keys Method

Microsoft® JScript™
Keys Method
See Also 		Language Reference

Exists Method
Items Method


Remove Method

Microsoft® JScript™
Remove Method 		Language Reference
Version 2

See Also Applies To

Description
Removes a key, item pair from a Dictionary object.
Syntax
object.Remove(key)

The Remove method syntax has these parts:

Part | Description
object | Required. Always the name of a Dictionary object.
key | Required. Key associated with the key, item pair you want to remove from the Dictionary object.

Remarks
An error occurs if the specified key, item pair does not exist.

The following code illustrates use of the Remove method:

var a, d, i, s;              // Create some variables.
d = new ActiveXObject("Scripting.Dictionary");
d.Add ("a", "Athens");       // Add some keys and items
d.Add ("b", "Belgrade");
d.Add ("c", "Cairo");
...
d.Remove("b");               // Remove second pair.


Remove Method

Microsoft® JScript™
Remove Method
Applies To 		Language Reference

Dictionary Object


RemoveAll Method

Microsoft® JScript™
RemoveAll Method 		Language Reference
Version 2

See Also Applies To

Description
The RemoveAll method removes all key, item pairs from a Dictionary object.
Syntax
object.RemoveAll( )

The object is always the name of a Dictionary object.

Remarks
The following code illustrates use of the RemoveAll method:

var a, d, i;             // Create some variables.
d = new ActiveXObject("Scripting.Dictionary");
d.Add ("a", "Athens");   // Add some keys and items.
d.Add ("b", "Belgrade");
d.Add ("c", "Cairo");
...
d.RemoveAll( );           // Clear the dictionary.


RemoveAll Method

Microsoft® JScript™
RemoveAll Method
Applies To 		Language Reference

Dictionary Object


RemoveAll Method

Microsoft® JScript™
RemoveAll Method
See Also 		Language Reference

Add Method
Remove Method


Remove Method

Microsoft® JScript™
Remove Method
See Also 		Language Reference

Add Method
RemoveAll Method


AvailableSpace Property

Microsoft® JScript™
AvailableSpace Property 		Language Reference
Version 3

See Also Applies To

Description
Returns the amount of space available to a user on the specified drive or network share.
Syntax
object.AvailableSpace

The object is always a Drive object.

Remarks
The value returned by the AvailableSpace property is typically the same as that returned by the FreeSpace property. Differences may occur between the two for computer systems that support quotas.

The following code illustrates the use of the AvailableSpace property:

function ShowAvailableSpace(drvPath)
{
    var fs, d, s;
    fs = new ActiveXObject("Scripting.FileSystemObject");
    d = fs.GetDrive(fs.GetDriveName(drvPath));
    s = "Drive " + drvPath.toUpperCase + " - ";
    s += d.VolumeName + "<br>";
    s += "Available Space: " + d.AvailableSpace/1024 + " Kbytes";
    Response.Write(s);
}


AvailableSpace Property

Microsoft® JScript™
AvailableSpace Property
Applies To 		Language Reference

Drive Object


AvailableSpace Property

Microsoft® JScript™
AvailableSpace Property
See Also 		Language Reference

DriveLetter Property
DriveType Property
FileSystem Property
FreeSpace Property
IsReady Property
Path Property
RootFolder Property
SerialNumber Property
ShareName Property
TotalSize Property
VolumeName Property


DriveLetter Property

Microsoft® JScript™
DriveLetter Property 		Language Reference
Version 3

See Also Applies To

Description
Returns the drive letter of a physical local drive or a network share. Read-only.
Syntax
object.DriveLetter

The object is always a Drive object.

Remarks
The DriveLetter property returns a zero-length string ("") if the specified drive is not associated with a drive letter, for example, a network share that has not been mapped to a drive letter.

The following code illustrates the use of the DriveLetter property:

function ShowDriveLetter(drvPath)
{
    var fs, d, s;
    fs = new ActiveXObject("Scripting.FileSystemObject");
    d = fs.GetDrive(fs.GetDriveName(drvPath));
    s = "Drive " + d.DriveLetter.toUpperCase( ) + ": - ";
    s += d.VolumeName + "<br>";
    s += "Available Space: " + d.AvailableSpace/1024 + " Kbytes";
    Response.Write(s);
}


DriveLetter Property

Microsoft® JScript™
DriveLetter Property
Applies To 		Language Reference

Drive Object


DriveLetter Property

Microsoft® JScript™
DriveLetter Property
See Also 		Language Reference

AvailableSpace Property
DriveType Property
FileSystem Property
FreeSpace Property
IsReady Property
Path Property
RootFolder Property
SerialNumber Property
ShareName Property
TotalSize Property
VolumeName Property


DriveType Property

Microsoft® JScript™
DriveType Property 		Language Reference
Version 3

See Also Applies To

Description
Returns a value indicating the type of a specified drive.
Syntax
object.DriveType

The object is always a Drive object.

Remarks
The following code illustrates the use of the DriveType property:
function ShowDriveType(drvpath)
{
    var fs, d, s, t;
    fs = new ActiveXObject("Scripting.FileSystemObject");
    d = fs.GetDrive(drvpath);
    switch (d.DriveType)
    {
        case 0: t = "Unknown"; break;
        case 1: t = "Removable"; break;
        case 2: t = "Fixed"; break;
        case 3: t = "Network"; break;
        case 4: t = "CD-ROM"; break;
        case 5: t = "RAM Disk"; break;
    }
    s = "Drive " + d.DriveLetter + ": - " + t;
    Response.Write(s);
}


DriveType Property

Microsoft® JScript™
DriveType Property
Applies To 		Language Reference

Drive Object


DriveType Property

Microsoft® JScript™
DriveType Property
See Also 		Language Reference

AvailableSpace Property
Driveetter Property
FileSystem Property
FreeSpace Property
IsReady Property
Path Property
RootFolder Property
SerialNumber Property
ShareName Property
TotalSize Property
VolumeName Property


FileSystem Property

Microsoft® JScript™
FileSystem Property 		Language Reference
Version 3

See Also Applies To

Description
Returns the type of file system in use for the specified drive.
Syntax
object.FileSystem

The object is always a Drive object.

Remarks
Available return types include FAT, NTFS, and CDFS.

The following code illustrates the use of the FileSystem property:

function ShowFileSystemType(drvPath)
{
    var fs,d, s;
    fs = new ActiveXObject("Scripting.FileSystemObject");
    d = fs.GetDrive(drvPath);
    s = d.FileSystem;
    Response.Write(s);
}


FileSystem Property

Microsoft® JScript™
FileSystem Property
Applies To 		Language Reference

Drive Object


FileSystem Property

Microsoft® JScript™
FileSystem Property
See Also 		Language Reference

AvailableSpace Property
DriveLetter Property
DriveType Property
FreeSpace Property
IsReady Property
Path Property
RootFolder Property
SerialNumber Property
ShareName Property
TotalSize Property
VolumeName Property


FreeSpace Property

Microsoft® JScript™
FreeSpace Property 		Language Reference
Version 3

See Also Applies To

Description
Returns the amount of free space available to a user on the specified drive or network share. Read-only.
Syntax
object.FreeSpace

The object is always a Drive object.

Remarks
The value returned by the FreeSpace property is typically the same as that returned by the AvailableSpace property. Differences may occur between the two for computer systems that support quotas.

The following code illustrates the use of the FreeSpace property:

function ShowFreeSpace(drvPath)
{
    var fs, d, s;
    fs = new ActiveXObject("Scripting.FileSystemObject");
    d = fs.GetDrive(fs.GetDriveName(drvPath));
    s = "Drive " + drvPath.toUpperCase( ) + " - ";
    s += d.VolumeName + "<br>";
    s += "Free Space: " + d.FreeSpace/1024 + " Kbytes";
    Response.Write(s);
}


FreeSpace Property

Microsoft® JScript™
FreeSpace Property
Applies To 		Language Reference

Drive Object


FreeSpace Property

Microsoft® JScript™
FreeSpace Property
See Also 		Language Reference

AvailableSpace Property
DriveLetter Property
DriveType Property
FileSystem Property
IsReady Property
Path Property
RootFolder Property
SerialNumber Property
ShareName Property
TotalSize Property
VolumeName Property


IsReady Property

Microsoft® JScript™
IsReady Property 		Language Reference
Version 3

See Also Applies To

Description
Returns True if the specified drive is ready; False if it is not.
Syntax
object.IsReady

The object is always a Drive object.

Remarks
For removable-media drives and CD-ROM drives, IsReady returns True only when the appropriate media is inserted and ready for access.

The following code illustrates the use of the IsReady property:

function ShowDriveInfo(drvpath)
{
    var fs, d, s, t;
    fs = new ActiveXObject("Scripting.FileSystemObject")
    d = fs.GetDrive(drvpath)
    switch (d.DriveType)
    {
      case 0: t = "Unknown"; break;
      case 1: t = "Removable"; break;
      case 2: t = "Fixed"; break;
      case 3: t = "Network"; break;
      case 4: t = "CD-ROM"; break;
      case 5: t = "RAM Disk"; break;
    }
    s = "Drive " + d.DriveLetter + ": - " + t;
    if (d.IsReady)
    {
        s += "<br>" + "Drive is Ready.";
    }
    else
    {
        s += "<br>" + "Drive is not Ready.";
    }
    Response.Write(s);
}


IsReady Property

Microsoft® JScript™
IsReady Property
Applies To 		Language Reference

Drive Object


IsReady Property

Microsoft® JScript™
IsReady Property
See Also 		Language Reference

AvailableSpace Property
DriveLetter Property
DriveType Property
FileSystem Property
FreeSpace Property
Path Property
RootFolder Property
SerialNumber Property
ShareName Property
TotalSize Property
VolumeName Property


Path Property

Microsoft® JScript™
Path Property 		Language Reference
Version 3

See Also Applies To

Description
Returns the path for a specified file, folder, or drive.
Syntax
object.Path

The object is always a File, Folder, or Drive object.

Remarks
For drive letters, the root drive is not included. For example, the path for the C drive is C:, not C:\.

The following code illustrates the use of the Path property with a File object:

function ShowFileAccessInfo(filespec)
{
    var fs, d, f, s;
    fs = new ActiveXObject("Scripting.FileSystemObject");
    f = fs.GetFile(filespec);
    s = f.Path.toUpperCase() + "<br>";
    s += "Created: " + f.DateCreated + "<br>";
    s += "Last Accessed: " + f.DateLastAccessed + "<br>";
    s += "Last Modified: " + f.DateLastModified
    Response.Write(s);
}


Path Property

Microsoft® JScript™
Path Property
Applies To 		Language Reference

Drive Object
File Object
Folder Object


Path Property

Microsoft® JScript™
Path Property
See Also 		Language Reference

Attributes Property
AvailableSpace Property
DateCreated Property
DateLastAccessed Property
DateLastModified Property
Drive Property
DriveLetter Property
DriveType Property
Files Property
FileSystem Property
FreeSpace Property
IsReady Property
IsRootFolder Property
Name Property
ParentFolder Property
RootFolder Property
SerialNumber Property
ShareName Property
ShortName Property
ShortPath Property
Size Property
SubFolders Property
TotalSize Property
Type Property
VolumeName Property


RootFolder Property

Microsoft® JScript™
RootFolder Property 		Language Reference
Version 3

See Also Applies To

Description
Returns a Folder object representing the root folder of a specified drive. Read-only.
Syntax
object.RootFolder

The object is always a Drive object.

Remarks
All the files and folders contained on the drive can be accessed using the returned Folder object.


RootFolder Property

Microsoft® JScript™
RootFolder Property
Applies To 		Language Reference

Drive Object


RootFolder Property

Microsoft® JScript™
RootFolder Property
See Also 		Language Reference

AvailableSpace Property
DriveLetter Property
DriveType Property
FileSystem Property
FreeSpace Property
IsReady Property
Path Property
SerialNumber Property
ShareName Property
TotalSize Property
VolumeName Property


SerialNumber Property

Microsoft® JScript™
SerialNumber Property 		Language Reference
Version 3

See Also Applies To

Description
Returns the decimal serial number used to uniquely identify a disk volume.
Syntax
object.SerialNumber

The object is always a Drive object.

Remarks
You can use the SerialNumber property to ensure that the correct disk is inserted in a drive with removable media.

The following code illustrates the use of the SerialNumber property:

function ShowDriveInfo(drvpath)
{
    var fs, d, s, t;
    fs = new ActiveXObject("Scripting.FileSystemObject");
    d = fs.GetDrive(fs.GetDriveName(fs.GetAbsolutePathName(drvpath)));
    switch (d.DriveType)
    {
      case 0: t = "Unknown"; break;
      case 1: t = "Removable"; break;
      case 2: t = "Fixed"; break;
      case 3: t = "Network"; break;
      case 4: t = "CD-ROM"; break;
      case 5: t = "RAM Disk"; break;
    }
    s = "Drive " + d.DriveLetter + ": - " + t;
    s += "<br>" + "SN: " + d.SerialNumber;
    Response.Write(s);
}


SerialNumber Property

Microsoft® JScript™
SerialNumber Property
Applies To 		Language Reference

Drive Object


SerialNumber Property

Microsoft® JScript™
SerialNumber Property
See Also 		Language Reference

AvailableSpace Property
DriveLetter Property
DriveType Property
FileSystem Property
FreeSpace Property
IsReady Property
Path Property
RootFolder Property
ShareName Property
TotalSize Property
VolumeName Property


ShareName Property

Microsoft® JScript™
ShareName Property 		Language Reference
Version 3

See Also Applies To

Description
Returns the network share name for a specified drive.
Syntax
object.ShareName

The object is always a Drive object.

Remarks
If object is not a network drive, the ShareName property returns a zero-length string ("").

The following code illustrates the use of the ShareName property:

function ShowDriveInfo(drvpath)
{
    var fs, d, s;
    fs = new ActiveXObject("Scripting.FileSystemObject");
    d = fs.GetDrive(fs.GetDriveName(fs.GetAbsolutePathName(drvpath)));
    s = "Drive " + d.DriveLetter + ": - " + d.ShareName;
    Response.Write(s);
}


ShareName Property

Microsoft® JScript™
ShareName Property
Applies To 		Language Reference

Drive Object


ShareName Property

Microsoft® JScript™
ShareName Property
See Also 		Language Reference

AvailableSpace Property
DriveLetter Property
DriveType Property
FileSystem Property
FreeSpace Property
IsReady Property
Path Property
RootFolder Property
SerialNumber Property
TotalSize Property
VolumeName Property


TotalSize Property

Microsoft® JScript™
TotalSize Property 		Language Reference
Version 3

See Also Applies To

Description
Returns the total space, in bytes, of a drive or network share.
Syntax
object.TotalSize

The object is always a Drive object.

Remarks
The following code illustrates the use of the TotalSize property:
function SpaceReport(drvPath)
{
    var fs, d, s;
    fs = new ActiveXObject("Scripting.FileSystemObject");
    d = fs.GetDrive(fs.GetDriveName(drvPath));
    s = "Drive " + drvPath + " - ";
    s += d.VolumeName + "<br>";
    s += "Total Space: "+ d.TotalSize/1024 + " Kbytes <br>";
    s += "Free Space:  " + d.FreeSpace/1024 + " Kbytes";
    Response.Write(s);
}


TotalSize Property

Microsoft® JScript™
TotalSize Property
Applies To 		Language Reference

Drive Object


TotalSize Property

Microsoft® JScript™
TotalSize Property
See Also 		Language Reference

AvailableSpace Property
DriveLetter Property
DriveType Property
FileSystem Property
FreeSpace Property
IsReady Property
Path Property
RootFolder Property
SerialNumber Property
ShareName Property
VolumeName Property


VolumeName Property

Microsoft® JScript™
VolumeName Property 		Language Reference
Version 3

See Also Applies To

Description
Sets or returns the volume name of the specified drive. Read/write.
Syntax
object.VolumeName [= newname]

The VolumeName property has these parts:

Part | Description
object | Required. Always the name of a Drive object.
newname | Optional. If provided, newname is the new name of the specified object.

Remarks
The following code illustrates the use of the VolumeName property:
function SpaceReport(drvPath)
{
    var fs, d, s;
    fs = new ActiveXObject("Scripting.FileSystemObject");
    d = fs.GetDrive(fs.GetDriveName(drvPath));
    s = "Drive " + drvPath + " - ";
    s += d.VolumeName + "<br>";
    s += "Total Space: "+ d.TotalSize/1024 + " Kbytes <br>";
    s += "Free Space:  " + d.FreeSpace/1024 + " Kbytes";
    Response.Write(s);
}


VolumeName Property

Microsoft® JScript™
VolumeName Property
Applies To 		Language Reference

Drive Object


VolumeName Property

Microsoft® JScript™
VolumeName Property
See Also 		Language Reference

AvailableSpace Property
DriveLetter Property
DriveType Property
FileSystem Property
FreeSpace Property
IsReady Property
Path Property
RootFolder Property
SerialNumber Property
ShareName Property
TotalSize Property


atEnd Method

Microsoft® JScript™
atEnd Method 		Language Reference
Version 3

See Also Applies To

Description
Returns a Boolean value indicating if the enumerator is at the end of the collection.
Syntax
myEnum.atEnd( )

The myEnum argument is any Enumerator object.

Return Value
The atEnd method returns true if the current item is the last one in the collection, the collection is empty, or the current item is undefined. Otherwise, it returns false.


atEnd Method

Microsoft® JScript™
atEnd Method
Applies To 		Language Reference

Enumerator Object


atEnd Method

Microsoft® JScript™
atEnd Method
See Also 		Language Reference

item Method
moveFirst Method
moveNext Method


item Method

Microsoft® JScript™
item Method 		Language Reference
Version 3

See Also Applies To

Description
Returns the current item in the collection.
Syntax
myEnum.item( )

The myEnum argument is any Enumerator object.

Return Value
The item method returns the current item. If the collection is empty or the current item is undefined, it returns undefined.


item Method

Microsoft® JScript™
item Method
Applies To 		Language Reference

Enumerator Object


item Method

Microsoft® JScript™
item Method
See Also 		Language Reference

atEnd Method
moveFirst Method
moveNext Method


moveFirst Method

Microsoft® JScript™
moveFirst Method 		Language Reference
Version 3

See Also Applies To

Description
Resets the current item in the collection to the first item.
Syntax
myEnum.moveFirst( )

The myEnum argument is any Enumerator object.

Remarks
If there are no items in the collection, the current item is set to undefined.


moveFirst Method

Microsoft® JScript™
moveFirst Method
Applies To 		Language Reference

Enumerator Object


moveFirst Method

Microsoft® JScript™
moveFirst Method
See Also 		Language Reference

atEnd Method
item Method
moveNext Method


moveNext Method

Microsoft® JScript™
moveNext Method 		Language Reference
Version 3

See Also Applies To

Description
Moves the current item to the next item in the collection.
Syntax
myEnum.moveNext( )

The myEnum argument is any Enumerator object.

Remarks
If the enumerator is at the end of the collection or the collection is empty, the current item is set to undefined.


moveNext Method

Microsoft® JScript™
moveNext Method
Applies To 		Language Reference

Enumerator Object


moveNext Method

Microsoft® JScript™
moveNext Method
See Also 		Language Reference

atEnd Method
item Method
moveFirst Method


JScript Error Messages

Microsoft® Jscript™
JScript Error Messages 		Language Reference

Error Code | Message
5 | Invalid procedure call or argument
6 | Overflow
7 | Out of memory
9 | Subscript out of range
10 | This array is fixed or temporarily locked
11 | Division by zero
13 | Type mismatch
14 | Out of string space
17 | Can't perform requested operation
28 | Out of stack space
35 | Sub or Function not defined
48 | Error in loading DLL
51 | Internal error
52 | Bad file name or number
53 | File not found
54 | Bad file mode
55 | File already open
57 | Device I/O error
58 | File already exists
61 | Disk full
62 | Input past end of file
67 | Too many files
68 | Device unavailable
70 | Permission denied
71 | Disk not ready
74 | Can't rename with different drive
75 | Path/File access error
76 | Path not found
91 | Object variable or With block variable not set
92 | For loop not initialized
93 | Invalid pattern string
94 | Invalid use of Null
322 | Can't create necessary temporary file
424 | Object required
429 | Automation server can't create object
430 | Class doesn't support Automation
432 | File name or class name not found during Automation operation
438 | Object doesn't support property or method <item>
440 | Automation error
445 | Object doesn't support this action
446 | Object doesn't support named arguments
447 | Object doesn't support current locale setting
448 | Named argument not found
449 | Argument not optional
450 | Wrong number of arguments or invalid property assignment
451 | Object not a collection
453 | Specified DLL function not found
458 | Variable uses an Automation type not supported in JScript
501 | Cannot assign to variable
502 | Object not safe for scripting
503 | Object not safe for initializing
504 | Object not safe for creating
5000 | Cannot assign to 'this'
5001 | <Item> is not a number; Number expected
5002 | <Item> is not a function; Function expected
5003 | Cannot assign to a function result
5004 | <Item> is not an indexable object; Cannot index object
5005 | <Item> is not a string; String expected
5006 | <Item> is not a date object; Date object expected
5007 | <Item> is not an object; Object expected
5008 | Cannot assign to <item>; Illegal assignment
5009 | <Item> is undefined; Undefined identifier
5010 | <Item> is not a boolean; Boolean expected
5011 | Can't execute code from a freed script
5012 | Cannot delete <item>; Object member expected
5013 | <Item> is not a VBArray; VBArray expected
5014 | <Item> is not a JScript object; JScript object expected
5015 | <Item> is not an enumerator object; Enumerator object expected
5016 | <Item> is not a regular expression object; Regular Expression object expected
5017 | Syntax error in regular expression
5018 | Unexpected quantifier
5019 | Expected ']' in regular expression
5020 | Expected ')' in regular expression
5021 | Invalid range in character set


Attributes Property

Microsoft® JScript™
Attributes Property 		Language Reference
Version 3

See Also Applies To

Description
Sets or returns the attributes of files or folders. Read/write or read-only, depending on the attribute.
Syntax
object.Attributes [= newattributes]

The Attributes property has these parts:

Part | Description
object | Required. Always the name of a File or Folder object.
newattributes | Optional. If provided, newattributes is the new value for the attributes of the specified object.

Settings
The newattributes argument can have any of the following values or any logical combination of the following values:

Constant | Value | Description
Normal | 0 | Normal file. No attributes are set.
ReadOnly | 1 | Read-only file. Attribute is read/write.
Hidden | 2 | Hidden file. Attribute is read/write.
System | 4 | System file. Attribute is read/write.
Volume | 8 | Disk drive volume label. Attribute is read-only.
Directory | 16 | Folder or directory. Attribute is read-only.
Archive | 32 | File has changed since last backup. Attribute is read/write.
Alias | 64 | Link or shortcut. Attribute is read-only.
Compressed | 128 | Compressed file. Attribute is read-only.

Remarks
The following code illustrates the use of the Attributes property with a file:
function ToggleArchiveBit(filespec)
{
    var fs, f, r, s;
    fs = new ActiveXObject("Scripting.FileSystemObject");
    f = fs.GetFile(filespec)
    if (f.attributes && 32)
    {
        f.attributes = f.attributes - 32;
        s = "Archive bit is cleared.";
    }
    else
    {
        f.attributes = f.attributes + 32;
        s =  "Archive bit is set.";
    }
    return s;
}


Attributes Property

Microsoft® JScript™
Attributes Property
Applies To 		Language Reference

File Object
Folder Object


Attributes Property

Microsoft® JScript™
Attributes Property
See Also 		Language Reference

DateCreated Property
DateLastAccessed Property
DateLastModified Property
Drive Property
Files Property
IsRootFolder Property
Name Property
ParentFolder Property
Path Property
ShortName Property
ShortPath Property
Size Property
SubFolders Property
Type Property


Copy Method

Microsoft® JScript™
Copy Method 		Language Reference
Version 3

See Also Applies To

Description
Copies a specified file or folder from one location to another.
Syntax
object.Copy( destination[, overwrite] );

The Copy method syntax has these parts:

Part | Description
object | Required. Always the name of a File or Folder object.
destination | Required. Destination where the file or folder is to be copied. Wildcard characters are not allowed.
overwrite | Optional. Boolean value that is True (default) if existing files or folders are to be overwritten; False if they are not.

Remarks
The results of the Copy method on a File or Folder are identical to operations performed using FileSystemObject.CopyFile or FileSystemObject.CopyFolder where the file or folder referred to by object is passed as an argument. You should note, however, that the alternative methods are capable of copying multiple files or folders.


Copy Method

Microsoft® JScript™
Copy Method
Applies To 		Language Reference

File Object
Folder Object


Copy Method

Microsoft® JScript™
Copy Method
See Also 		Language Reference

CopyFile Method
CopyFolder Method
Delete Method
Move Method
OpenAsTextStream Method


CreateTextFile Method

Microsoft® JScript™
CreateTextFile Method 		Language Reference
Version 2

See Also Applies To

Description
Creates a specified file name and returns a TextStream object that can be used to read from or write to the file.

Syntax
object.CreateTextFile(filename[, overwrite[, unicode]])

The CreateTextFile method has these parts:

Part | Description
object | Required. Always the name of a FileSystemObject or Folder object.
filename | Required. String expression that identifies the file to create.
overwrite | Optional. Boolean value that indicates whether you can overwrite an existing file. The value is true if the file can be overwritten, false if it can't be overwritten. If omitted, existing files are not overwritten.
unicode | Optional. Boolean value that indicates whether the file is created as a Unicode or ASCII file. The value is true if the file is created as a Unicode file, false if it's created as an ASCII file. If omitted, an ASCII file is assumed.

Remarks
The following code illustrates how to use the CreateTextFile method to create and open a text file:
var fs = new ActiveXObject("Scripting.FileSystemObject");
var a = fs.CreateTextFile("c:\\testfile.txt", true);
a.WriteLine("This is a test.");
a.Close();
If the overwrite argument is false, or is not provided, for a filename that already exists, an error occurs.


CreateTextFile Method

Microsoft® JScript™
CreateTextFile Method
Applies To 		Language Reference

FileSystemObject Object
Folder Object


CreateTextFile Method

Microsoft® JScript™
CreateTextFile Method
See Also 		Language Reference

CreateFolder Method
OpenAsTextStream Method
OpenTextFile Method


DateCreated Property

Microsoft® JScript™
DateCreated Property 		Language Reference
Version 3

See Also Applies To

Description
Returns the date and time that the specified file or folder was created. Read-only.
Syntax
object.DateCreated

The object is always a File or Folder object.

Remarks
The following code illustrates the use of the DateCreated property with a file:
function ShowFileInfo(filespec)
{
    var fs, f, s;
    fs = new ActiveXObject("Scripting.FileSystemObject");
    f = fs.GetFile(filespec);
    s = "Created: " + f.DateCreated;
    Response.Write(s);
}


DateCreated Property

Microsoft® JScript™
DateCreated Property
Applies To 		Language Reference

File Object
Folder Object


DateCreated Property

Microsoft® JScript™
DateCreated Property
See Also 		Language Reference

Attributes Property
DateLastAccessed Property
DateLastModified Property
Drive Property
Files Property
IsRootFolder Property
Name Property
ParentFolder Property
Path Property
ShortName Property
ShortPath Property
Size Property
SubFolders Property
Type Property


DateLastAccessed Property

Microsoft® JScript™
DateLastAccessed Property 		Language Reference
Version 3

See Also Applies To

Description
Returns the date and time that the specified file or folder was last accessed. Read-only.
Syntax
object.DateLastAccessed

The object is always a File or Folder object.

Remarks
The following code illustrates the use of the DateLastAccessed property with a file:
function ShowFileAccessInfo(filespec)
{
    var fs, f, s;
    fs = new ActiveXObject("Scripting.FileSystemObject");
    f = fs.GetFile(filespec);
    s = filespec.toUpperCase() + "<br>";
    s += "Created: " + f.DateCreated + "<br>";
    s += "Last Accessed: " + f.DateLastAccessed + "<br>";
    s += "Last Modified: " + f.DateLastModified;
    Response.Write(s);
}
Important This method depends on the underlying operating system for its behavior. If the operating system does not support providing time information, none will be returned.


DateLastAccessed Property

Microsoft® JScript™
DateLastAccessed Property
Applies To 		Language Reference

File Object
Folder Object


DateLastAccessed Property

Microsoft® JScript™
DateLastAccessed Property
See Also 		Language Reference

Attributes Property
DateCreated Property
DateLastModified Property
Drive Property
Files Property
IsRootFolder Property
Name Property
ParentFolder Property
Path Property
ShortName Property
ShortPath Property
Size Property
SubFolders Property
Type Property


DateLastModified Property

Microsoft® JScript™
DateLastModified Property 		Language Reference
Version 3

See Also Applies To

Description
Returns the date and time that the specified file or folder was last modified. Read-only.
Syntax
object.DateLastModified

The object is always a File or Folder object.

Remarks
The following code illustrates the use of the DateLastModified property with a file:
function ShowFileAccessInfo(filespec)
{
    var fs, f, s;
    fs = new ActiveXObject("Scripting.FileSystemObject");
    f = fs.GetFile(filespec);
    s = filespec.toUpperCase() + "<br>";
    s += "Created: " + f.DateCreated + "<br>";
    s += "Last Accessed: " + f.DateLastAccessed + "<br>";
    s += "Last Modified: " + f.DateLastModified;
    Response.Write(s);
}


DateLastModified Property

Microsoft® JScript™
DateLastModified Property
Applies To 		Language Reference

File Object
Folder Object


DateLastModified Property

Microsoft® JScript™
DateLastModified Property
See Also 		Language Reference

Attributes Property
DateCreated Property
DateLastAccessed Property
Drive Property
Files Property
IsRootFolder Property
Name Property
ParentFolder Property
Path Property
ShortName Property
ShortPath Property
Size Property
SubFolders Property
Type Property


Delete Method

Microsoft® JScript™
Delete Method 		Language Reference
Version 3

See Also Applies To

Description
Deletes a specified file or folder.
Syntax
object.Delete( force );

The Delete method syntax has these parts:

Part | Description
object | Required. Always the name of a File or Folder object.
force | Optional. Boolean value that is True if files or folders with the read-only attribute set are to be deleted; False (default) if they are not.

Remarks
An error occurs if the specified file or folder does not exist.

The results of the Delete method on a File or Folder are identical to operations performed using FileSystemObject.DeleteFile or FileSystemObject.DeleteFolder.

The Delete method does not distinguish between folders that have contents and those that do not. The specified folder is deleted regardless of whether or not it has contents.


Delete Method

Microsoft® JScript™
Delete Method
Applies To 		Language Reference

File Object
Folder Object


Delete Method

Microsoft® JScript™
Delete Method
See Also 		Language Reference

Copy Method
DeleteFile Method
DeleteFolder Method
Move Method
OpenAsTextStream Method


Drive Property

Microsoft® JScript™
Drive Property 		Language Reference
Version 3

See Also Applies To

Description
Returns the drive letter of the drive on which the specified file or folder resides. Read-only.
Syntax
object.Drive

The object is always a File or Folder object.

Remarks
The following code illustrates the use of the Drive property:
function ShowFileAccessInfo(filespec)
{
    var fs, f, s;
    fs = new ActiveXObject("Scripting.FileSystemObject");
    f = fs.GetFile(filespec);
    s = f.Name + " on Drive " + f.Drive + "<br>";
    s += "Created: " + f.DateCreated + "<br>";
    s += "Last Accessed: " + f.DateLastAccessed + "<br>";
    s += "Last Modified: " + f.DateLastModified;
    Response.Write(s);
}


Drive Property

Microsoft® JScript™
Drive Property
Applies To 		Language Reference

File Object
Folder Object


Drive Property

Microsoft® JScript™
Drive Property
See Also 		Language Reference

Attributes Property
DateCreated Property
DateLastAccessed Property
DateLastModified Property
Files Property
IsRootFolder Property
Name Property
ParentFolder Property
Path Property
ShortName Property
ShortPath Property
Size Property
SubFolders Property
Type Property


Move Method

Microsoft® JScript™
Move Method 		Language Reference
Version 3

See Also Applies To

Description
Moves a specified file or folder from one location to another.
Syntax
object.Move( destination );

The Move method syntax has these parts:

Part | Description
object | Required. Always the name of a File or Folder object.
destination | Required. Destination where the file or folder is to be moved. Wildcard characters are not allowed.

Remarks
The results of the Move method on a File or Folder are identical to operations performed using FileSystemObject.MoveFile or FileSystemObject.MoveFolder. You should note, however, that the alternative methods are capable of moving multiple files or folders.


Move Method

Microsoft® JScript™
Move Method
Applies To 		Language Reference

File Object
Folder Object


Move Method

Microsoft® JScript™
Move Method
See Also 		Language Reference

Copy Method
Delete Method
MoveFile Method
MoveFolder Method
OpenAsTextStream Method


Name Property

Microsoft® JScript™
Name Property 		Language Reference
Version 3

See Also Applies To

Description
Sets or returns the name of a specified file or folder. Read/write.
Syntax
object.Name [= newname]

The Name property has these parts:

Part | Description
object | Required. Always the name of a File or Folder object.
newname | Optional. If provided, newname is the new name of the specified object.

Remarks
The following code illustrates the use of the Name property:
function ShowFileAccessInfo(filespec)
{
    var fs, f, s;
    fs = new ActiveXObject("Scripting.FileSystemObject");
    f = fs.GetFile(filespec);
    s = f.Name + " on Drive " + f.Drive + "<br>";
    s += "Created: " + f.DateCreated + "<br>";
    s += "Last Accessed: " + f.DateLastAccessed + "<br>";
    s += "Last Modified: " + f.DateLastModified;
    Response.Write(s);
}


Name Property

Microsoft® JScript™
Name Property
Applies To 		Language Reference

File Object
Folder Object


Name Property

Microsoft® JScript™
Name Property
See Also 		Language Reference

Attributes Property
DateCreated Property
DateLastAccessed Property
DateLastModified Property
Drive Property
Files Property
IsRootFolder Property
ParentFolder Property
Path Property
ShortName Property
ShortPath Property
Size Property
SubFolders Property
Type Property


OpenAsTextStream Method

Microsoft® JScript™
OpenAsTextStream Method 		Language Reference
Version 3

See Also Applies To

Description
Opens a specified file and returns a TextStream object that can be used to read from, write to, or append to the file.
Syntax
object.OpenAsTextStream([iomode, [format]])

The OpenAsTextStream method syntax has these parts:

Part | Description
object | Required. Always the name of a File object.
iomode | Optional. Indicates input/output mode. Can be one of three constants: ForReading, ForWriting, or ForAppending.
format | Optional. One of three Tristate values used to indicate the format of the opened file. If omitted, the file is opened as ASCII.

Settings
The iomode argument can have any of the following settings:

Constant | Value | Description
ForReading | 1 | Open a file for reading only. You can't write to this file.
ForWriting | 2 | Open a file for writing. If a file with the same name exists, its previous contents are overwritten.
ForAppending | 8 | Open a file and write to the end of the file.

The format argument can have any of the following settings:

Constant | Value | Description
TristateUseDefault | -2 | Opens the file using the system default.
TristateTrue | -1 | Opens the file as Unicode.
TristateFalse | 0 | Opens the file as ASCII.

Remarks
The OpenAsTextStream method provides the same functionality as the OpenTextFile method of the FileSystemObject. In addition, the OpenAsTextStream method can be used to write to a file.

The following code illustrates the use of the OpenAsTextStream method:

function TextStreamTest( )
{
    var ForReading = 1, ForWriting = 2, ForAppending = 3;
    var TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0;
    var fs, f, ts, s;
    fs = new ActiveXObject("Scripting.FileSystemObject");
    fs.CreateTextFile( "test1.txt" );           // Create a file
    f = fs.GetFile("test1.txt");
    ts = f.OpenAsTextStream(ForWriting, TristateUseDefault);
    ts.Write( "Hello World" );
    ts.Close( );
    ts = f.OpenAsTextStream(ForReading, TristateUseDefault);
    s = ts.ReadLine( );
    ts.Close( );
    Response.Write(s);
}


OpenAsTextStream Method

Microsoft® JScript™
OpenAsTextStream Method
Applies To 		Language Reference

File Object


OpenAsTextStream Method

Microsoft® JScript™
OpenAsTextStream Method
See Also 		Language Reference

Copy Method
CreateTextFile Method
Delete Method
Move Method
OpenTextFile Method


OpenTextFile Method

Microsoft® JScript™
OpenTextFile Method 		Language Reference
Version 2

See Also Applies To

Description
Opens a specified file and returns a TextStream object that can be used to read from or append to the file.
Syntax
object.OpenTextFile(filename[, iomode[, create[, format]]])

The OpenTextFile method has these parts:

Part | Description
object | Required. Object is always the name of a FileSystemObject.
filename | Required. String expression that identifies the file to open.
iomode | Optional. Constant, either ForReading (2) or ForAppending (8), indicating that the file is open for reading or appending.
create | Optional. Boolean value that indicates whether a new file can be created if the specified filename doesn't exist. The value is True if a new file is created, False if it isn't created. If omitted, a new file isn't created.
format | Optional. One of three Tristate values used to indicate the format of the opened file. If omitted, the file is opened as ASCII.

Settings
The format argument can have any of the following settings:

Value | Description
TristateTrue | Open the file as Unicode.
TristateFalse | Open the file as ASCII.
TristateUseDefault | Open the file using the system default.

Remarks
The following code illustrates the use of the OpenTextFile method to open a file for appending text:

var fs, a, ForAppending;
ForAppending = 8;
fs = new ActiveXObject("Scripting.FileSystemObject");
a = fs.OpenTextFile("c:\\testfile.txt", ForAppending, false);
...
a.Close();


OpenTextFile Method

Microsoft® JScript™
OpenTextFile Method
Applies To 		Language Reference

FileSystemObject Object


OpenTextFile Method

Microsoft® JScript™
OpenTextFile Method
See Also 		Language Reference

CreateTextFile Method
OpenAsTextStream Method


ParentFolder Property

Microsoft® JScript™
ParentFolder Property 		Language Reference
Version 3

See Also Applies To

Description
Returns the folder object for the parent of the specified file or folder. Read-only.
Syntax
object.ParentFolder

The object is always a File or Folder object.

Remarks
The following code illustrates the use of the ParentFolder property with a file:
function ShowFileAccessInfo(filespec)
{
    var fs, f, s;
    fs = new ActiveXObject("Scripting.FileSystemObject");
    f = fs.GetFile(filespec);
    s = f.Name + " in " + f.ParentFolder + "<br>";
    s += "Created: " + f.DateCreated + "<br>";
    s += "Last Accessed: " + f.DateLastAccessed + "<br>";
    s += "Last Modified: " + f.DateLastModified;
    Response.Write(s);
}


ParentFolder Property

Microsoft® JScript™
ParentFolder Property
Applies To 		Language Reference

File Object
Folder Object


ParentFolder Property

Microsoft® JScript™
ParentFolder Property
See Also 		Language Reference

Attributes Property
DateCreated Property
DateLastAccessed Property
DateLastModified Property
Drive Property
Files Property
IsRootFolder Property
Name Property
Path Property
ShortName Property
ShortPath Property
Size Property
SubFolders Property
Type Property


ShortName Property

Microsoft® JScript™
ShortName Property 		Language Reference
Version 3

See Also Applies To

Description
Returns the short name used by programs that require the earlier 8.3 naming convention.
Syntax
object.ShortName

The object is always a File or Folder object.

Remarks
The following code illustrates the use of the ShortName property with a File object:
function ShowShortName(filespec)
{
    var fs, f, s;
    fs = new ActiveXObject("Scripting.FileSystemObject");
    f = fs.GetFile(filespec);
    s = "The short name for " + "" + f.Name;
    s += "" + "<br>";
    s += "is: " + "" + f.ShortName + "";
    Response.Write(s);
}


ShortName Property

Microsoft® JScript™
ShortName Property
Applies To 		Language Reference

File Object
Folder Object


ShortName Property

Microsoft® JScript™
ShortName Property
See Also 		Language Reference

Attributes Property
DateCreated Property
DateLastAccessed Property
DateLastModified Property
Drive Property
Files Property
IsRootFolder Property
Name Property
ParentFolder Property
Path Property
ShortPath Property
Size Property
SubFolders Property
Type Property


ShortPath Property

Microsoft® JScript™
ShortPath Property 		Language Reference
Version 3

See Also Applies To

Description
Returns the short path used by programs that require the earlier 8.3 file naming convention.
Syntax
object.ShortPath

The object is always a File or Folder object.

Remarks
The following code illustrates the use of the ShortName property with a File object:
function ShowShortPath(filespec);
{
    var fs, f, s;
    fs = new ActiveXObject("Scripting.FileSystemObject");
    f = fs.GetFile(filespec);
    s = "The short path for " + "" + f.Name;
    s += "" + "<br>";
    s += "is: " + "" + f.ShortPath + "";
    Response.Write(s);
}


ShortPath Property

Microsoft® JScript™
ShortPath Property
Applies To 		Language Reference

File Object
Folder Object


ShortPath Property

Microsoft® JScript™
ShortPath Property
See Also 		Language Reference

Attributes Property
DateCreated Property
DateLastAccessed Property
DateLastModified Property
Drive Property
Files Property
IsRootFolder Property
Name Property
ParentFolder Property
Path Property
ShortName Property
Size Property
SubFolders Property
Type Property


Size Property

Microsoft® JScript™
Size Property 		Language Reference
Version 3

See Also Applies To

Description
For files, returns the size, in bytes, of the specified file. For folders, returns the size, in bytes, of all files and subfolders contained in the folder.
Syntax
object.Size

The object is always a File or Folder object.

Remarks
The following code illustrates the use of the Size property with a Folder object:
function ShowFolderSize(filespec)
{
    var fs, f, s;
    fs = new ActiveXObject("Scripting.FileSystemObject");
    f = fs.GetFolder(filespec);
    s = f.Name + " uses " + f.size + " bytes.";
    Response.Write(s);
}


Size Property

Microsoft® JScript™
Size Property
Applies To 		Language Reference

File Object
Folder Object


Size Property

Microsoft® JScript™
Size Property
See Also 		Language Reference

Attributes Property
DateCreated Property
DateLastAccessed Property
DateLastModified Property
Drive Property
Files Property
IsRootFolder Property
Name Property
ParentFolder Property
Path Property
ShortName Property
ShortPath Property
SubFolders Property
Type Property


BuildPath Method

Microsoft® JScript™
BuildPath Method 		Language Reference
Version 3

See Also Applies To

Description
Appends a name to an existing path.
Syntax
object.BuildPath(path, name)

The BuildPath method syntax has these parts:

Part | Description
object | Required. Always the name of a FileSystemObject.
path | Required. Existing path to which name is appended. Path can be absolute or relative and need not specify an existing folder.
name | Required. Name being appended to the existing path.

Remarks
The BuildPath method inserts an additional path separator between the existing path and the name, only if necessary.


BuildPath Method

Microsoft® JScript™
BuildPath Method
Applies To 		Language Reference

FileSystemObject Object


BuildPath Method

Microsoft® JScript™
BuildPath Method
See Also 		Language Reference

GetAbsolutePathName Method
GetBaseName Method
GetDriveName Method
GetExtensionName Method
GetFileName Method
GetParentFolderName Method
GetTempName Method


CopyFile Method

Microsoft® JScript™
CopyFile Method 		Language Reference
Version 3

See Also Applies To

Description
Copies one or more files from one location to another.
Syntax
object.CopyFile ( source, destination[, overwrite] )

The CopyFile method syntax has these parts:

Part | Description
object | Required. The object is always the name of a FileSystemObject.
source | Required. Character string file specification, which can include wildcard characters, for one or more files to be copied.
destination | Required. Character string destination where the file or files from source are to be copied. Wildcard characters are not allowed.
overwrite | Optional. Boolean value that indicates if existing files are to be overwritten. If true, files are overwritten; if false, they are not. The default is true. Note that CopyFile will fail if destination has the read-only attribute set, regardless of the value of overwrite.

Remarks
Wildcard characters can only be used in the last path component of the source argument. For example, you can use:
fs = new ActiveXObject("Scripting.FileSystemObject");
fs.CopyFile ("c:\\mydocuments\\letters\\*.doc", "c:\\tempfolder\\")
But you can't use:
fs = new ActiveXObject("Scripting.FileSystemObject");
fs.CopyFile ("c:\\mydocuments\\*\\R1???97.xls", "c:\\tempfolder")
If source contains wildcard characters or destination ends with a path separator (\), it is assumed that destination is an existing folder in which to copy matching files. Otherwise, destination is assumed to be the name of a file to create. In either case, three things can happen when an individual file is copied.
  • If destination does not exist, source gets copied. This is the usual case.
  • If destination is an existing file, an error occurs if overwrite is false. Otherwise, an attempt is made to copy source over the existing file.
  • If destination is a directory, an error occurs.
An error also occurs if a source using wildcard characters doesn't match any files. The CopyFile method stops on the first error it encounters. No attempt is made to roll back or undo any changes made before an error occurs.


CopyFile Method

Microsoft® JScript™
CopyFile Method
Applies To 		Language Reference

FileSystemObject Object


CopyFile Method

Microsoft® JScript™
CopyFile Method
See Also 		Language Reference

Copy Method
CopyFolder Method
CreateTextFile Method
DeleteFile Method
MoveFile Method


CopyFolder Method

Microsoft® JScript™
CopyFolder Method 		Language Reference
Version 3

See Also Applies To

Description
Recursively copies a folder from one location to another.
Syntax
object.CopyFolder ( source, destination[, overwrite] );

The CopyFolder method syntax has these parts:

Part | Description
object | Required. Always the name of a FileSystemObject.
source | Required. Character string folder specification, which can include wildcard characters, for one or more folders to be copied.
destination | Required. Character string destination where the folder and subfolders from source are to be copied. Wildcard characters are not allowed.
overwrite | Optional. Boolean value that indicates if existing folders are to be overwritten. If true, files are overwritten; if false, they are not. The default is true.

Remarks
Wildcard characters can only be used in the last path component of the source argument. For example, you can use:
fs = new ActiveXObject("Scripting.FileSystemObject");
fs.CopyFolder ("c:\\mydocuments\\letters\\*", "c:\\tempfolder\\")
But you can't use:
fs = new ActiveXObject("Scripting.FileSystemObject");
fs.CopyFolder ("c:\\mydocuments\\*\\*", "c:\\tempfolder\\")
If source contains wildcard characters or destination ends with a path separator (\), it is assumed that destination is an existing folder in which to copy matching folders and subfolders. Otherwise, destination is assumed to be the name of a folder to create. In either case, four things can happen when an individual folder is copied.
  • If destination does not exist, the source folder and all its contents gets copied. This is the usual case.
  • If destination is an existing file, an error occurs.
  • If destination is a directory, an attempt is made to copy the folder and all its contents. If a file contained in source already exists in destination, an error occurs if overwrite is false. Otherwise, it will attempt to copy the file over the existing file.
  • If destination is a read-only directory, an error occurs if an attempt is made to copy an existing read-only file into that directory and overwrite is false.
An error also occurs if a source using wildcard characters doesn't match any folders.

The CopyFolder method stops on the first error it encounters. No attempt is made to roll back any changes made before an error occurs.


CopyFolder Method

Microsoft® JScript™
CopyFolder Method
Applies To 		Language Reference

FileSystemObject Object


CopyFolder Method

Microsoft® JScript™
CopyFolder Method
See Also 		Language Reference

CopyFile Method
Copy Method
CreateFolder Method
DeleteFolder Method
MoveFolder Method


CreateFolder Method

Microsoft® JScript™
CreateFolder Method 		Language Reference
Version 3

See Also Applies To

Description
Creates a folder.
Syntax
object.CreateFolder(foldername)

The CreateFolder method has these parts:

Part | Description
object | Required. Always the name of a FileSystemObject.
foldername | Required. String expression that identifies the folder to create.

Remarks
An error occurs if the specified folder already exists.

The following code illustrates how to use the CreateFolder method to create a folder:

var fs = new ActiveXObject("Scripting.FileSystemObject");
var a = fs.CreateFolder("c:\\new folder");


CreateFolder Method

Microsoft® JScript™
CreateFolder Method
Applies To 		Language Reference

FileSystemObject Object


CreateFolder Method

Microsoft® JScript™
CreateFolder Method
See Also 		Language Reference

CopyFolder Method
DeleteFolder Method
MoveFolder Method


DeleteFile Method

Microsoft® JScript™
DeleteFile Method 		Language Reference
Version 3

See Also Applies To

Description
Deletes a specified file.
Syntax
object.DeleteFile ( filespec[, force] );

The DeleteFile method syntax has these parts:

Part | Description
object | Required. Always the name of a FileSystemObject.
filespec | Required. The name of the file to delete. The filespec can contain wildcard characters in the last path component.
force | Optional. Boolean value that is true if files with the read-only attribute set are to be deleted; false (default) if they are not.

Remarks
An error occurs if no matching files are found. The DeleteFile method stops on the first error it encounters. No attempt is made to roll back or undo any changes that were made before an error occurred.


DeleteFile Method

Microsoft® JScript™
DeleteFile Method
Applies To 		Language Reference

FileSystemObject Object


DeleteFile Method

Microsoft® JScript™
DeleteFile Method
See Also 		Language Reference

CopyFile Method
CreateTextFile Method
Delete Method
DeleteFolder Method
MoveFile Method


DeleteFolder Method

Microsoft® JScript™
DeleteFolder Method 		Language Reference
Version 3

See Also Applies To

Description
Deletes a specified folder and its contents.
Syntax
object.DeleteFolder ( folderspec[, force] );

The DeleteFolder method syntax has these parts:

Part | Description
object | Required. Always the name of a FileSystemObject.
folderspec | Required. The name of the folder to delete. The folderspec can contain wildcard characters in the last path component.
force | Optional. Boolean value that is true if folders with the read-only attribute set are to be deleted; false (default) if they are not.

Remarks
The DeleteFolder method does not distinguish between folders that have contents and those that do not. The specified folder is deleted regardless of whether or not it has contents.

An error occurs if no matching folders are found. The DeleteFolder method stops on the first error it encounters. No attempt is made to roll back or undo any changes that were made before an error occurred.


DeleteFolder Method

Microsoft® JScript™
DeleteFolder Method
Applies To 		Language Reference

FileSystemObject Object


DeleteFolder Method

Microsoft® JScript™
DeleteFolder Method
See Also 		Language Reference

CopyFolder Method
CreateFolder Method
Delete Method
DeleteFile Method
MoveFolder Method


DriveExists Method

Microsoft® JScript™
DriveExists Method 		Language Reference
Version 3

See Also Applies To

Description
Returns True if the specified drive exists; False if it does not.
Syntax
object.DriveExists(drivespec)

The DriveExists method syntax has these parts:

Part | Description
object | Required. Always the name of a FileSystemObject.
drivespec | Required. A drive letter or a complete path specification.

Remarks
For drives with removable media, the DriveExists method returns true even if there are no media present. Use the IsReady property of the Drive object to determine if a drive is ready.


DriveExists Method

Microsoft® JScript™
DriveExists Method
Applies To 		Language Reference

FileSystemObject Object


DriveExists Method

Microsoft® JScript™
DriveExists Method
See Also 		Language Reference

Drive Object
Drives Collection
FileExists Method
FolderExists Method
GetDrive Method
GetDriveName Method
IsReady Property


Drives Property

Microsoft® JScript™
Drives Property 		Language Reference
Version 3

See Also Applies To

Description
Returns a Drives collection consisting of all Drive objects available on the local machine.
Syntax
object.Drives

The object is always a FileSystemObject.

Remarks
Removable-media drives need not have media inserted for them to appear in the Drives collection.

You can iterate the members of the Drives collection using the Enumerator object and the for statement:

function ShowDriveList()
{
    var fs, s, n, e, x;
    fs = new ActiveXObject("Scripting.FileSystemObject");
    e = new Enumerator(fs.Drives);
    s = "";
    for (; !e.atEnd(); e.moveNext())
    {
        x = e.item();
        s = s + x.DriveLetter;
        s += " - ";
        if (x.DriveType == 3)
             n = x.ShareName;
        else if (x.IsReady)
             n = x.VolumeName;
        else
             n = "[Drive not ready]";
        s +=  n + "<br>";
    }
    Response.Write(s);
}


Drives Property

Microsoft® JScript™
Drives Property
Applies To 		Language Reference

FileSystemObject Object


Drives Property

Microsoft® JScript™
Drives Property
See Also 		Language Reference

Drives Collection
Files Property
SubFolders Property


FileExists Method

Microsoft® JScript™
FileExists Method 		Language Reference
Version 3

See Also Applies To

Description
Returns True if a specified file exists; False if it does not.
Syntax
object.FileExists(filespec)

The FileExists method syntax has these parts:

Part | Description
object | Required. Always the name of a FileSystemObject.
filespec | Required. The name of the file whose existence is to be determined. A complete path specification (either absolute or relative) must be provided if the file isn't expected to exist in the current folder.


FileExists Method

Microsoft® JScript™
FileExists Method
Applies To 		Language Reference

FileSystemObject Object


FileExists Method

Microsoft® JScript™
FileExists Method
See Also 		Language Reference

DriveExists Method
FolderExists Method
GetFile Method
GetFileName Method


FolderExists Method

Microsoft® JScript™
FolderExists Method 		Language Reference
Version 3

See Also Applies To

Description
Returns True if a specified folder exists; False if it does not.
Syntax
object.FolderExists(folderspec)

The FolderExists method syntax has these parts:

Part | Description
object | Required. Always the name of a FileSystemObject.
folderspec | Required. The name of the folder whose existence is to be determined. A complete path specification (either absolute or relative) must be provided if the folder isn't expected to exist in the current folder.


FolderExists Method

Microsoft® JScript™
FolderExists Method
Applies To 		Language Reference

FileSystemObject Object


FolderExists Method

Microsoft® JScript™
FolderExists Method
See Also 		Language Reference

DriveExists Method
FileExists Method
GetFolder Method
GetParentFolderName Method


GetAbsolutePathName Method

Microsoft® JScript™
GetAbsolutePathName Method 		Language Reference
Version 3

See Also Applies To

Description
Returns a complete and unambiguous path from a provided path specification.
Syntax
object.GetAbsolutePathName(pathspec)

The GetAbsolutePathName method syntax has these parts:

Part | Description
object | Required. Always the name of a FileSystemObject.
pathspec | Required. Path specification to change to a complete and unambiguous path.

Remarks
A path is complete and unambiguous if it provides a complete reference from the root of the specified drive. A complete path can only end with a path separator character (\) if it specifies the root folder of a mapped drive.

Assuming the current directory is c:\mydocuments\reports, the following table illustrates the behavior of the GetAbsolutePathName method.

pathspec | Returned path
"c:" | "c:\mydocuments\reports"
"c:.." | "c:\mydocuments"
"c:\\\\\\" | "c:\"
"c:*.*\\may97" | "c:\mydocuments\reports\*.*\may97"
"region1" | "c:\mydocuments\reports\region1"
"c:\\..\\..\\mydocuments" | "c:\mydocuments"


GetAbsolutePathName Method

Microsoft® JScript™
GetAbsolutePathName Method
Applies To 		Language Reference

FileSystemObject Object


GetAbsolutePathName Method

Microsoft® JScript™
GetAbsolutePathName Method
See Also 		Language Reference

GetBaseName Method
GetDrive Method
GetDriveName Method
GetExtensionName Method
GetFile Method
GetFileName Method
GetFolder Method
GetParentFolderName Method
GetSpecialFolder Method
GetTempName Method


GetBaseName Method

Microsoft® JScript™
GetBaseName Method 		Language Reference
Version 3

See Also Applies To

Description
Returns a string containing the base name of the last component, less any file extension, in a path.
Syntax
object.GetBaseName(path)

The GetBaseName method syntax has these parts:

Part | Description
object | Required. Always the name of a FileSystemObject.
path | Required. The path specification for the component whose base name is to be returned.

Remarks
The GetBaseName method returns a zero-length string ("") if no component matches the path argument.
Note The GetBaseName method works only on the provided path string. It does not attempt to resolve the path, nor does it check for the existence of the specified path.


GetBaseName Method

Microsoft® JScript™
GetBaseName Method
Applies To 		Language Reference

FileSystemObject Object


GetBaseName Method

Microsoft® JScript™
GetBaseName Method
See Also 		Language Reference

GetAbsolutePathName Method
GetDrive Method
GetDriveName Method
GetExtensionName Method
GetFile Method
GetFileName Method
GetFolder Method
GetParentFolderName Method
GetSpecialFolder Method
GetTempName Method


GetDrive Method

Microsoft® JScript™
GetDrive Method 		Language Reference
Version 3

See Also Applies To

Description
Returns a Drive object corresponding to the drive in a specified path.
Syntax
object.GetDrive ( drivespec );

The GetDrive method syntax has these parts:

Part | Description
object | Required. Always the name of a FileSystemObject.
drivespec | Required. The drivespec argument can be a drive letter (c), a drive letter with a colon appended (c:), a drive letter with a colon and path separator appended (c:\), or any network share specification (\\computer2\share1).

Remarks
For network shares, a check is made to ensure that the share exists.

An error occurs if drivespec does not conform to one of the accepted forms or does not exist.

To call the GetDrive method on a normal path string, use the following sequence to get a string that is suitable for use as drivespec:

DriveSpec = GetDriveName(GetAbsolutePathName(Path))


GetDrive Method

Microsoft® JScript™
GetDrive Method
Applies To 		Language Reference

FileSystemObject Object


GetDrive Method

Microsoft® JScript™
GetDrive Method
See Also 		Language Reference

GetAbsolutePathName Method
GetBaseName Method
GetDriveName Method
GetExtensionName Method
GetFile Method
GetFileName Method
GetFolder Method
GetParentFolderName Method
GetSpecialFolder Method
GetTempName Method


GetDriveName Method

Microsoft® JScript™
GetDriveName Method 		Language Reference
Version 3

See Also Applies To

Description
Returns a string containing the name of the drive for a specified path.
Syntax
object.GetDriveName(path)

The GetDriveName method syntax has these parts:

Part | Description
object | Required. Always the name of a FileSystemObject.
path | Required. The path specification for the component whose drive name is to be returned.

Remarks
The GetDriveName method returns a zero-length string ("") if the drive can't be determined.
Note The GetDriveName method works only on the provided path string. It does not attempt to resolve the path, nor does it check for the existence of the specified path.


GetDriveName Method

Microsoft® JScript™
GetDriveName Method
Applies To 		Language Reference

FileSystemObject Object


GetDriveName Method

Microsoft® JScript™
GetDriveName Method
See Also 		Language Reference

GetAbsolutePathName Method
GetBaseName Method
GetDrive Method
GetExtensionName Method
GetFile Method
GetFileName Method
GetFolder Method
GetParentFolderName Method
GetSpecialFolder Method
GetTempName Method


GetExtensionName Method

Microsoft® JScript™
GetExtensionName Method 		Language Reference
Version 3

See Also Applies To

Description
Returns a string containing the extension name for the last component in a path.
Syntax
object.GetExtensionName(path)

The GetExtensionName method syntax has these parts:

Part | Description
object | Required. Always the name of a FileSystemObject.
path | Required. The path specification for the component whose extension name is to be returned.

Remarks
For network drives, the root directory (\) is considered to be a component.

The GetExtensionName method returns a zero-length string ("") if no component matches the path argument.


GetExtensionName Method

Microsoft® JScript™
GetExtensionName Method
Applies To 		Language Reference

FileSystemObject Object


GetExtensionName Method

Microsoft® JScript™
GetExtensionName Method
See Also 		Language Reference

GetAbsolutePathName Method
GetBaseName Method
GetDrive Method
GetDriveName Method
GetFile Method
GetFileName Method
GetFolder Method
GetParentFolderName Method
GetSpecialFolder Method
GetTempName Method


GetFile Method

Microsoft® JScript™
GetFile Method 		Language Reference
Version 3

See Also Applies To

Description
Returns a File object corresponding to the file in a specified path.
Syntax
object.GetFile(filespec)

The GetFile method syntax has these parts:

Part | Description
object | Required. Always the name of a FileSystemObject.
filespec | Required. The filespec is the path (absolute or relative) to a specific file.

Remarks
An error occurs if the specified file does not exist.


GetFile Method

Microsoft® JScript™
GetFile Method
Applies To 		Language Reference

FileSystemObject Object


GetFile Method

Microsoft® JScript™
GetFile Method
See Also 		Language Reference

GetAbsolutePathName Method
GetBaseName Method
GetDrive Method
GetDriveName Method
GetExtensionName Method
GetFileName Method
GetFolder Method
GetParentFolderName Method
GetSpecialFolder Method
GetTempName Method


GetFileName Method

Microsoft® JScript™
GetFileName Method 		Language Reference
Version 3

See Also Applies To

Description
Returns the last component of specified path that is not part of the drive specification.
Syntax
object.GetFileName(pathspec)

The GetFileName method syntax has these parts:

Part | Description
object | Required. Always the name of a FileSystemObject.
pathspec | Required. The path (absolute or relative) to a specific file.

Remarks
The GetFileName method returns a zero-length string ("") if pathspec does not end with the named component.
Note The GetFileName method works only on the provided path string. It does not attempt to resolve the path, nor does it check for the existence of the specified path.


GetFileName Method

Microsoft® JScript™
GetFileName Method
See Also 		Language Reference

GetAbsolutePathName Method
GetBaseName Method
GetDrive Method
GetDriveName Method
GetExtensionName Method
GetFile Method
GetFolder Method
GetParentFolderName Method
GetSpecialFolder Method
GetTempName Method


GetFolder Method

Microsoft® JScript™
GetFolder Method 		Language Reference
Version 3

See Also Applies To

Description
Returns a Folder object corresponding to the folder in a specified path.
Syntax
object.GetFolder(folderspec)

The GetFolder method syntax has these parts:

Part | Description
object | Required. Always the name of a FileSystemObject.
folderspec | Required. The folderspec is the path (absolute or relative) to a specific folder.

Remarks
An error occurs if the specified folder does not exist.


GetFolder Method

Microsoft® JScript™
GetFolder Method
Applies To 		Language Reference

FileSystemObject Object


GetFolder Method

Microsoft® JScript™
GetFolder Method
See Also 		Language Reference

GetAbsolutePathName Method
GetBaseName Method
GetDrive Method
GetDriveName Method
GetExtensionName Method
GetFile Method
GetFileName Method
GetParentFolderName Method
GetSpecialFolder Method
GetTempName Method


GetParentFolderName Method

Microsoft® JScript™
GetParentFolderName Method 		Language Reference
Version 3

See Also Applies To

Description
Returns a string containing the name of the parent folder of the last component in a specified path.
Syntax
object.GetParentFolderName(path)

The GetParentFolderName method syntax has these parts:

Part | Description
object | Required. Always the name of a FileSystemObject.
path | Required. The path specification for the component whose parent folder name is to be returned.

Remarks
The GetParentFolderName method returns a zero-length string ("") if there is no parent folder for the component specified in the path argument.
Note The GetParentFolderName method works only on the provided path string. It does not attempt to resolve the path, nor does it check for the existence of the specified path.


GetParentFolderName Method

Microsoft® JScript™
GetParentFolderName Method
Applies To 		Language Reference

FileSystemObject Object


GetParentFolder Method

Microsoft® JScript™
GetParentFolder Method
See Also 		Language Reference

GetAbsolutePathName Method
GetBaseName Method
GetDrive Method
GetDriveName Method
GetExtensionName Method
GetFile Method
GetFileName Method
GetFolder Method
GetSpecialFolder Method
GetTempName Method


GetSpecialFolder Method

Microsoft® JScript™
GetSpecialFolder Method 		Language Reference
Version 3

See Also Applies To

Description
Returns the special folder specified.
Syntax
object.GetSpecialFolder(folderspec)

The GetSpecialFolder method syntax has these parts:

Part | Description
object | Required. Always the name of a FileSystemObject.
folderspec | Required. The name of the special folder to be returned. Can be any of the constants shown in the Settings section.

Settings
The folderspec argument can have any of the following values:

Constant | Value | Description
WindowsFolder | 0 | The Windows folder contains files installed by the Windows operating system.
SystemFolder | 1 | The System folder contains libraries, fonts, and device drivers.
TemporaryFolder | 2 | The Temp folder is used to store temporary files. Its path is found in the TMP environment variable.


GetSpecialFolder Method

Microsoft® JScript™
GetSpecialFolder Method
Applies To 		Language Reference

FileSystemObject Object


GetSpecialFolder Method

Microsoft® JScript™
GetSpecialFolder Method
See Also 		Language Reference

GetAbsolutePathName Method
GetBaseName Method
GetDrive Method
GetDriveName Method
GetExtensionName Method
GetFile Method
GetFileName Method
GetFolder Method
GetParentFolderName Method
GetTempName Method


GetTempName Method

Microsoft® JScript™
GetTempName Method 		Language Reference
Version 3

See Also Applies To

Description
Returns a randomly generated temporary file or folder name that is useful for performing operations that require a temporary file or folder.
Syntax
object.GetTempName ( );

The optional object is always the name of a FileSystemObject.

Remarks
The GetTempName method does not create a file. It provides only a temporary file name that can be used with CreateTextFile to create a file.


GetTempName Method

Microsoft® JScript™
GetTempName Method
Applies To 		Language Reference

FileSystemObject Object


GetTempName Method

Microsoft® JScript™
GetTempName Method
See Also 		Language Reference

GetAbsolutePathName Method
GetBaseName Method
GetDrive Method
GetDriveName Method
GetExtensionName Method
GetFile Method
GetFileName Method
GetFolder Method
GetParentFolderName Method
GetSpecialFolder Method


MoveFile Method

Microsoft® JScript™
MoveFile Method 		Language Reference
Version 3

See Also Applies To

Description
Moves one or more files from one location to another.
Syntax
object.MoveFile ( source, destination );

The MoveFile method syntax has these parts:

Part | Description
object | Required. Always the name of a FileSystemObject.
source | Required. The path to the file or files to be moved. The source argument string can contain wildcard characters in the last path component only.
destination | Required. The path where the file or files are to be moved. The destination argument can't contain wildcard characters.

Remarks
If source contains wildcards or destination ends with a path separator (\), it is assumed that destination specifies an existing folder in which to move the matching files. Otherwise, destination is assumed to be the name of a destination file to create. In either case, three things can happen when an individual file is moved:
  • If destination does not exist, the file gets moved. This is the usual case.
  • If destination is an existing file, an error occurs.
  • If destination is a directory, an error occurs.

An error also occurs if a wildcard character that is used in source doesn't match any files. The MoveFile method stops on the first error it encounters. No attempt is made to roll back any changes made before the error occurs.
Important This method allows moving files between volumes only if supported by the operating system.


MoveFile Method

Microsoft® JScript™
MoveFile Method
Applies To 		Language Reference

FileSystemObject Object


MoveFile Method

Microsoft® JScript™
MoveFile Method
See Also 		Language Reference

CopyFile Method
DeleteFile Method
GetFile Method
GetFileName Method
Move Method
MoveFolder Method
OpenTextFile Method


MoveFolder Method

Microsoft® JScript™
MoveFolder Method 		Language Reference
Version 3

See Also Applies To

Description
Moves one or more folders from one location to another.
Syntax
object.MoveFolder ( source, destination );

The MoveFolder method syntax has these parts:

Part | Description
object | Required. Always the name of a FileSystemObject.
source | Required. The path to the folder or folders to be moved. The source argument string can contain wildcard characters in the last path component only.
destination | Required. The path where the folder or folders are to be moved. The destination argument can't contain wildcard characters.

Remarks
If source contains wildcards or destination ends with a path separator (\), it is assumed that destination specifies an existing folder in which to move the matching files. Otherwise, destination is assumed to be the name of a destination folder to create. In either case, three things can happen when an individual folder is moved:
  • If destination does not exist, the folder gets moved. This is the usual case.
  • If destination is an existing file, an error occurs.
  • If destination is a directory, an error occurs.

An error also occurs if a wildcard character that is used in source doesn't match any folders. The MoveFolder method stops on the first error it encounters. No attempt is made to roll back any changes made before the error occurs.
Important This method allows moving folders between volumes only if supported by the operating system.


MoveFolder Method

Microsoft® JScript™
MoveFolder Method
Applies To 		Language Reference

FileSystemObject Object


MoveFolder Method

Microsoft® JScript™
MoveFolder Method
See Also 		Language Reference

CopyFile Method
DeleteFile Method
GetFile Method
GetFileName Method
Move Method
MoveFile Method
OpenTextFile Method


Type Property

Microsoft® JScript™
Type Property 		Language Reference
Version 3

See Also Applies To

Description
Returns information about the type of a file or folder. For example, for files ending in .TXT, "Text Document" is returned.
Syntax
object.Type

The object is always a File or Folder object.

Remarks
The following code illustrates the use of the Type property to return a folder type. In this example, try providing the path of the Recycle Bin or other unique folder to the procedure.
function ShowFileType(filespec)
{
    var fs, f, s;
    fs = new ActiveXObject("Scripting.FileSystemObject");
    if (fs.FolderExists(filespec))
        f = fs.GetFolder(filespec);
    else if (fs.FileExists(filespec))
        f = fs.GetFile(filespec);
    else
        s = "File or Folder does not exist.";
    s = f.Name + " is a " + f.Type;
    Response.Write(s);
}


Type Property

Microsoft® JScript™
Type Property
Applies To 		Language Reference

File Object


Type Property

Microsoft® JScript™
Type Property
See Also 		Language Reference

Attributes Property
DateCreated Property
DateLastAccessed Property
DateLastModified Property
Drive Property
Files Property
IsRootFolder Property
Name Property
ParentFolder Property
Path Property
ShortName Property
ShortPath Property
Size Property
SubFolders Property


GetObject Function

Microsoft® JScript™
GetObject Function 		Language Reference
Version 3

See Also

Description
Returns a reference to an Automation object from a file.
Syntax
GetObject([pathname] [, class])

The GetObject function syntax has these parts:

Part | Description
pathname | Optional. Full path and name of the file containing the object to retrieve. If pathname is omitted, class is required.
class | Optional. Class of the object.

The class argument uses the syntax appname.objectype and has these parts:

Part | Description
appname | Required. Name of the application providing the object.
objectype | Required. Type or class of object to create.

Remarks
Use the GetObject function to access an Automation object from a file and assign the object to an object variable. Assign the object returned by GetObject to the object variable. For example:

var CADObject;
CADObject = GetObject("C:\\CAD\\SCHEMA.CAD");
When this code is executed, the application associated with the specified pathname is started, and the object in the specified file is activated. If pathname is a zero-length string (""), GetObject returns a new object instance of the specified type. If the pathname argument is omitted, GetObject returns a currently active object of the specified type. If no object of the specified type exists, an error occurs.

Some applications allow you to activate part of a file. Add an exclamation point (!) to the end of the file name and follow it with a string that identifies the part of the file you want to activate. For information on how to create this string, see the documentation for the application that created the object.

For example, in a drawing application you might have multiple layers to a drawing stored in a file. You could use the following code to activate a layer within a drawing called SCHEMA.CAD:

var LayerObject = GetObject("C:\\CAD\\SCHEMA.CAD!Layer3");
If you don't specify the object's class, Automation determines the application to start and the object to activate, based on the file name you provide. Some files, however, may support more than one class of object. For example, a drawing might support three different types of objects: an Application object, a Drawing object, and a Toolbar object, all of which are part of the same file. To specify which object in a file you want to activate, use the optional class argument. For example:

var MyObject;
MyObject = GetObject("C:\\DRAWINGS\\SAMPLE.DRW", "FIGMENT.DRAWING");
In the preceding example, FIGMENT is the name of a drawing application and DRAWING is one of the object types it supports. Once an object is activated, you reference it in code using the object variable you defined. In the preceding example, you access properties and methods of the new object using the object variable MyObject. For example:
MyObject.Line(9, 90);
MyObject.InsertText(9, 100, "Hello, world.");
MyObject.SaveAs("C:\\DRAWINGS\\SAMPLE.DRW");
Note Use the GetObject function when there is a current instance of the object or if you want to create the object with a file already loaded. If there is no current instance, and you don't want the object started with a file loaded, use the ActiveXObject object.

If an object has registered itself as a single-instance object, only one instance of the object is created, no matter how many times ActiveXObject is executed. With a single-instance object, GetObject always returns the same instance when called with the zero-length string ("") syntax, and it causes an error if the pathname argument is omitted.


GetObject Function

Microsoft® JScript™
GetObject Function
See Also 		Language Reference

ActiveXObject Object


ScriptEngine Function

Microsoft® JScript™
ScriptEngine Function 		Language Reference
Version 2

See Also

Description
Returns a string representing the scripting language in use.

Syntax
ScriptEngine( );
Return Values
The ScriptEngine function can return any of the following strings:

Part | Description
JScript | Indicates that Microsoft® JScript is the current script engine.
VBA | Indicates that Microsoft Visual Basic® for Applications is the current script engine.
VBScript | Indicates that Microsoft Visual Basic Scripting Edition is the current script engine.


ScriptEngineBuildVersion Function

Microsoft® JScript™
ScriptEngineBuildVersion Function 		Language Reference
Version 2

See Also

Description
Returns the build version number of the script engine in use.
Syntax
ScriptEngineBuildVersion( );

Return Values
The return value corresponds directly to the version information contained in the DLL for the scripting language in use.


ScriptEngineBuildVersion Function

Microsoft® JScript™
ScriptEngineBuildVersion Function
See Also 		Language Reference

ScriptEngine Function
ScriptEngineMajorVersion Function
ScriptEngineMinorVersion Function


ScriptEngine Function

Microsoft® JScript™
ScriptEngine Function
See Also 		Language Reference

ScriptEngineBuildVersion Function
ScriptEngineMajorVersion Function
ScriptEngineMinorVersion Function


ScriptEngineMajorVersion Function

Microsoft® JScript™
ScriptEngineMajorVersion Function 		Language Reference
Version 2

See Also

Description
Returns the major version number of the script engine in use.
Syntax
ScriptEngineMajorVersion( );
Return Values
The return value corresponds directly to the version information contained in the DLL for the scripting language in use.


ScriptEngineMajorVersion Function

Microsoft® JScript™
ScriptEngineMajorVersion Function
See Also 		Language Reference

ScriptEngine Function
ScriptEngineBuildVersion Function
ScriptEngineMinorVersion Function


ScriptEngineMinorVersion Function

Microsoft® JScript™
ScriptEngineMinorVersion Function 		Language Reference
Version 2

See Also

Description
Returns the minor version number of the script engine in use.
Syntax
ScriptEngineMinorVersion( );
Return Values
The return value corresponds directly to the version information contained in the DLL for the scripting language in use.


ScriptEngineMinorVersion Function

Microsoft® JScript™
ScriptEngineMinorVersion Function
See Also 		Language Reference

ScriptEngine Function
ScriptEngineBuildVersion Function
ScriptEngineMajorVersion Function


AddFolders Method

Microsoft® JScript™
AddFolders Method 		Language Reference
Version 3

See Also Applies To

Description
Adds a new Folder to a Folders collection.
Syntax
object.AddFolders ( folderName );

The AddFolders method has the following parts:

Part | Description
object | Required. Always the name of a Folders collection.
folderName | Required. The name of the new Folder being added.

Remarks
An error occurs if the folderName already exists.


AddFolders Method

Microsoft® JScript™
AddFolders Method
Applies To 		Language Reference

Folders Collection


AddFolders Method

Microsoft® JScript™
AddFolders Method
See Also 		Language Reference

Add Method


Files Property

Microsoft® JScript™
Files Property 		Language Reference
Version 3

See Also Applies To

Description
Returns a Files collection consisting of all File objects contained in the specified folder, including those with hidden and system file attributes set.
Syntax
object.Files

The object is always a Folder object.

Remarks
The following code illustrates the use of the Files property:
function ShowFolderFileList(folderspec)
{
    var fs, f, f1, fc, s;
    fs = new ActiveXObject("Scripting.FileSystemObject");
    f = fs.GetFolder(folderspec);
    fc = new Enumerator(f.files);
    s = "";
    for (; !fc.atEnd(); fc.moveNext())
    {
        s += fc.item();
        s += "<br>";
    }
    Response.Write(s);
}


Files Property

Microsoft® JScript™
Files Property
Applies To 		Language Reference

Folder Object


Files Property

Microsoft® Visual Basic® Scripting Edition
Files Property
See Also 		Language Reference

Attributes Property
DateCreated Property
DateLastAccessed Property
DateLastModified Property
Drive Property
IsRootFolder Property
Name Property
ParentFolder Property
Path Property
ShortName Property
ShortPath Property
Size Property
SubFolders Property
Type Property


IsRootFolder Property

Microsoft® JScript™
IsRootFolder Property 		Language Reference
Version 3

See Also Applies To

Description
Returns True if the specified folder is the root folder; False if it is not.
Syntax
object.IsRootFolder

The object is always a Folder object.

Remarks
The following code illustrates the use of the IsRootFolder property:
function DisplayLevelDepth(pathspec)
{
    var fs, f, n;
    fs = new ActiveXObject("Scripting.FileSystemObject");
    f = fs.GetFolder(pathspec);
    n = 0;
    if (f.IsRootFolder)
        Response.Write("The specified folder is the root folder.")
    else
    {
        do
        {
            f = f.ParentFolder;
            n++;
        }
        while (!f.IsRootFolder)
        Response.Write("The specified folder is nested " + n + " levels deep.")
    }
 }


IsRootFolder Property

Microsoft® JScript™
IsRootFolder Property
Applies To 		Language Reference

Folder Object


IsRootFolder Property

Microsoft® JScript™
IsRootFolder Property
See Also 		Language Reference

Attributes Property
DateCreated Property
DateLastAccessed Property
DateLastModified Property
Drive Property
Files Property
Name Property
ParentFolder Property
Path Property
ShortName Property
ShortPath Property
Size Property
SubFolders Property
Type Property


SubFolders Property

Microsoft® JScript™
SubFolders Property 		Language Reference
Version 3

See Also Applies To

Description
Returns a Folders collection consisting of all folders contained in a specified folder, including those with Hidden and System file attributes set.
Syntax
object.SubFolders

The object is always a Folder object.

Remarks
The following code illustrates the use of the SubFolders property:
function ShowFolderList(folderspec)
{
    var fs, f, f1, fc, s;
    fs = new ActiveXObject("Scripting.FileSystemObject");
    f = fs.GetFolder(folderspec);
    fc = new Enumerator(f.SubFolders);
    s = "";
    for (;!fc.atEnd(); fc.moveNext())
    {
        s += fc.item();
        s += "<br>";
    }
    Response.Write(s);
}


SubFolders Property

Microsoft® JScript™
SubFolders Property
Applies To 		Language Reference

Folder Object


SubFolders Property

Microsoft® JScript™
SubFolders Property
See Also 		Language Reference

Attributes Property
DateCreated Property
DateLastAccessed Property
DateLastModified Property
Drive Property
Files Property
IsRootFolder Property
Name Property
ParentFolder Property
Path Property
ShortName Property
ShortPath Property
Size Property
Type Property


arguments Property

Microsoft® JScript™
arguments Property 		Language Reference
Version 2

See Also Applies To

Description
An array containing each argument passed to the currently executing function.
Syntax
function.arguments[ ]

The function argument is the name of the currently executing function.

Remarks
The arguments property allows a graceful way for functions to handle a variable number of arguments. The length property of the array contains the number of arguments passed to the function.


arguments Property

Microsoft® JScript™
arguments Property
Applies To 		Language Reference

Function Object


arguments Property

Microsoft® JScript™
arguments Property
See Also 		Language Reference

function Statement
length Property (Array)


caller Property

Microsoft® JScript™
caller Property 		Language Reference
Version 2

See Also Applies To

Description
Contains a reference to the function that invoked the current function.
Syntax
functionname.caller

Remarks
The caller property is only defined for a function while that function is executing. If the function is called from the top level of a JScript program, caller contains null.


caller Property

Microsoft® JScript™
caller Property
Applies To 		Language Reference

Function Object


caller Property

Microsoft® JScript™
caller Property
See Also 		Language Reference

function Statement


length Property (Function)

Microsoft® JScript™
length Property (Function) 		Language Reference
Version 2

See Also Applies To

Description
Contains the number of arguments a function is defined with.
Syntax
functionname.length

The functionname argument is required and is the name of the function in question.

Remarks
The length property of a function is initialized by the scripting engine to the number of arguments in the function's definition when an instance of the function is created.

What happens when a function is called with a number of arguments different from the value of its length property depends on the function.


length Property

Microsoft® JScript™
length Property (Function)
Applies To 		Language Reference

Function Object


length Property

Microsoft® JScript™
length Property
See Also 		Language Reference

arguments Property
length Property (Array)
length Property (String)


toString Method (Function)

Microsoft® JScript™
toString Method (Function) 		Language Reference
Version 2

See Also Applies To

Description
Returns a string representation of a Function object.
Syntax
functionname.toString( )

The functionname argument is the Function object for which a string representation is sought.

Remarks
The string returned by the toString method is of the following form, where functionname is the name of the function whose toString method was called:
function functionname( ) { [native code] }


toString Method (Function)

Microsoft® JScript™
toString Method (Function)
Applies To 		Language Reference

Function Object


toString Method (Function)

Microsoft® JScript™
toString Method (Function)
See Also 		Language Reference

function Statement
toString Method (Number)


escape Method

Microsoft® JScript™
escape Method 		Language Reference
Version 1

See Also Applies To

Description

Encodes String objects so they can be read on all computers.

Syntax
escape(charstring)

The charstring argument is a String object to be encoded.

Remarks
The escape method returns a new String object (in Unicode format) that contains the contents of charstring. All spaces, punctuation, accented characters, and any other non-ASCII characters are replaced with %xx encoding, where xx is equivalent to the hexadecimal number representing the character. For example, a space is returned as "%20."

Characters with a value greater than 255 are stored using the %u xxxx format.


escape Method

Microsoft® JScript™
escape Method
Applies To 		Language Reference

Global Object


escape Method

Microsoft® JScript™
escape Method
See Also 		Language Reference

String Object
unescape Method


eval Method

Microsoft® JScript™
eval Method 		Language Reference
Version 1

See Also Applies To

Description
Evaluates JScript code.
Syntax
eval(codestring)

The codestring argument is a String object that contains valid JScript code. This string is parsed by the JScript parser and executed.

Remarks

The eval function allows dynamic execution of JScript source code. For example, the following code creates a new variable mydate that contains a Date object:

eval("var mydate = new Date();");
The code passed to the eval method is executed in the same context as the call to the eval method.


eval Method

Microsoft® JScript™
eval Method
Applies To 		Language Reference

Global Object


eval Method

Microsoft® JScript™
eval Method
See Also 		Language Reference

String Object


Infinity Property

Microsoft® JScript™
Infinity Property 		Language Reference
Version 3

See Also Applies To

Description
Contains an initial value of Number.POSITIVE_INFINITY.
Syntax
Infinity
Remarks
The Infinity property is a member of the Global object, and is made available when the scripting engine is initialized.


Infinity Property

Microsoft® JScript™
Infinity Property
Applies To 		Language Reference

Global Object


Infinity Property

Microsoft® JScript™
Infinity Property
See Also 		Language Reference

POSITIVE_INFINITY Property
NEGATIVE_INFINITY Property


isFinite Method

Microsoft® JScript™
isFinite Method 		Language Reference
Version 3

See Also Applies To

Description
Determines if a supplied number is finite.
Syntax
isFinite(number)

The number argument is a required numeric value.

Remarks
The isFinite method returns true if number is any value other than NaN, negative infinity, or positive infinity. In those three cases, it returns false.


isFinite Method

Microsoft® JScript™
isFinite Method
Applies To 		Language Reference

Global Object


isFinite Method

Microsoft® JScript™
isFinite Method
See Also 		Language Reference

isNaN Method


isNaN Method

Microsoft® JScript™
isNaN Method 		Language Reference
Version 1

See Also Applies To

Description
Determines whether a value is the reserved value NaN (not a number).
Syntax

isNaN(numvalue)

The numvalue argument is the value to be tested against NaN.

Remarks
The isNaN function returns true if the value is NaN, and false otherwise. You typically use this function to test return values from the parseInt and parseFloat methods.

Alternatively, a variable could be compared to itself. If it compares as unequal it is NaN. This is because NaN is the only value which is not equal to itself.


isNaN Method

Microsoft® JScript™
isNaN Method
Applies To 		Language Reference

Global Object


isNaN Method

Microsoft® JScript™
isNaN Method
See Also 		Language Reference

isFinite Method
NaN Property (Global)
parseFloat Method
parseInt Method


NaN Property (Global)

Microsoft® JScript™
NaN Property (Global) 		Language Reference
Version 3

See Also Applies To

Description
Contains an initial value of NaN.
Syntax
NaN
Remarks
The NaN property (not a number) is a member of the Global object, and is made available when the scripting engine is initialized.


NaN Property

Microsoft® JScript™
NaN Property
Applies To 		Language Reference

Global Object


NaN Property

Microsoft® JScript™
NaN Property
See Also 		Language Reference

isNaN Method


parseFloat Method

Microsoft® JScript™
parseFloat Method 		Language Reference
Version 1

See Also Applies To

Description
Converts strings into floating point numbers.
Syntax
parseFloat(numstring)

The numstring argument is a string that contains a floating point number.

Remarks
The parseFloat method returns an numerical value equal to the number contained in numstring. If no prefix of numstring can be successfully parsed into a floating point number, NaN (not a number) is returned.
parseFloat("abc")    // Returns NaN.
parseFloat("1.2abc") // Returns 1.2.

You can test for NaN using the isNaN method.


parseFloat Method

Microsoft® JScript™
parseFloat Method
Applies To 		Language Reference

Global Object


parseFloat Method

Microsoft® JScript™
parseFloat Method
See Also 		Language Reference

isNaN Method
parseInt Method
String Object


parseInt Method

Microsoft® JScript™
parseInt Method 		Language Reference
Version 1

See Also Applies To

Description
Converts strings into integers.
Syntax
parseInt(numstring, [radix])

The parseInt method syntax has these parts:

Part | Description
numstring | Required. A string to convert into a number.
radix | Optional. A value between 2 and 36 indicating the base of the number contained in numstring. If not supplied, strings with a prefix of '0x' are considered hexidecimal and strings with a prefix of '0' are considered octal. All other strings are considered decimal.

Remarks
The parseInt method returns an integer value equal to the number contained in numstring. If no prefix of numstring can be successfully parsed into an integer, NaN (not a number) is returned.
parseInt("abc")    // Returns NaN.
parseInt("12abc")  // Returns 12.

You can test for NaN using the isNaN method.


parseInt Method

Microsoft® JScript™
parseInt Method
Applies To 		Language Reference

Global Object


parseInt Method

Microsoft® JScript™
parseInt Method
See Also 		Language Reference

isNaN Method
parseFloat Method
String Object
valueOf Method


unescape Method

Microsoft® JScript™
unescape Method 		Language Reference
Version 1

See Also Applies To

Description
Decodes String objects encoded with the escape method.
Syntax
unescape(charstring)

The charstring argument is a String object to be decoded.

Remarks
The unescape method returns a new String object that contains the contents of charstring. All characters encoded with the %xx hexadecimal form are replaced by their ASCII character set equivalents.

Characters encoded in %u xxxx format (Unicode characters) are replaced with the Unicode character with hexadecimal encoding xxxx.


unescape Method

Microsoft® JScript™
unescape Method
Applies To 		Language Reference

Global Object


unescape Method

Microsoft® JScript™
unescape Method
See Also 		Language Reference

escape Method
String Object


JScript Comparison Operators

Microsoft® JScript™
Comparison Operators 		Language Reference
Version 1

See Also

Description
Returns a Boolean value indicating the result of the comparison.
Syntax
expression1 comparisonoperator expression2

The Comparison operator syntax has these parts:

Part | Description
expression1 | Any expression.
comparisonoperator | Any comparison operator.
expression2 | Any expression.

Remarks
When comparing strings, JScript uses the Unicode character value of the string expression.

The following is how the different groups of operators behave depending on the types and values of expression1 and expression2:

Relational (<, >, <=, >=)

  • Attempt to convert both expression1 and expression2 into numbers.
  • If both expressions are strings, do a lexicographical string comparison.
  • If either expression is NaN, return false.
  • Negative zero equals Positive zero.
  • Negative Infinity is less than everything including itself.
  • Positive Infinity is greater than everything including itself.
Equality (==, !=)
  • If the types of the two expressions are different, attempt to convert them to string, number, or Boolean.
  • NaN is not equal to anything including itself.
  • Negative zero equals positive zero.
  • null equals both null and undefined.
  • Values are considered equal if they are identical strings, numerically equivalent numbers, the same object, identical Boolean values, or (if different types) they can be coerced into one of these situations.
  • Every other comparison is considered unequal.
Identity (===. !==)

These operators behave identically to the equality operators except no type conversion is done, and the types must be the same to be considered equal.


Comparison Operators

Microsoft® JScript™
Comparison Operators
See Also 		Language Reference

Operator Behavior
Operator Precedence
Operator Summary


Microsoft JScript Features - ECMA

Microsoft® JScript™
Microsoft JScript Features
ECMA 		Language Reference

Contents

Category | Feature/Keyword
Array Handling Array
join, length, reverse, sort
Assignments Assign (=)
Compound Assign (OP=)
Booleans Boolean
Comments | /*...*/ or //
Constants/Literals NaN
null
true, false
Infinity
undefined
Control flow break
continue
for
for...in
if...else
return
while
Dates and Time Date
getDate, getDay, getFullYear, getHours, getMilliseconds, getMinutes, getMonth, getSeconds, getTime, getTimezoneOffset, getYear,
getUTCDate, getUTCDay, getUTCFullYear, getUTCHours, getUTCMilliseconds, getMinutes, getUTCMonth, getUTCSeconds,
setDate, setFullYear, setHours, setMilliseconds, setMinutes, setMonth, setSeconds, setTime, setYear,
setUTCDate, setUTCFullYear, setUTCHours, setUTCMilliseconds, setMinutes, setUTCMonth, setUTCSeconds,
toGMTString, toLocaleString, toUTCString, parse, UTC
Declarations function
new
this
var
with
Function Creation Function
arguments, length
Global Methods Global
escape, unescape
eval
isFinite, isNaN
parseInt, parseFloat
Math Math
abs, acos, asin, atan, atan2, ceil, cos, exp, floor, log, max, min, pow, random, round, sin, sqrt tan,
E, LN2, LN10, LOG2E, LOG10E, PI, SQRT1_2, SQRT2,
Numbers Number
MAX_VALUE, MIN_VALUE
NaN
NEGATIVE_INFINITY, POSITIVE_INFINITY,
Object Creation Object
new
constructor, prototype, toString, valueOf
Operators Addition (+), Subtraction (-)
Modulus arithmetic (%)
Multiplication (*), Division (/)
Negation (-)
Equality (==), Inequality (!=)
Less Than (<), Less Than or Equal To (<=)
Greater Than (>), Greater Than or Equal To (>=)
 Logical And(&&), Or (||), Not (!)
Bitwise And (&), Or (|), Not (~), Xor (^)
Bitwise Left Shift (<<), Shift Right (>>)
Unsigned Shift Right (>>>)
Conditional (?:)
Comma (,)
delete, typeOf, void
Decrement (--), Increment (++)
Objects Array
Boolean
Date
Function
Global
Math
Number
Object
String
Strings String
charAt, charCodeAt, fromCharCode
indexOf, lastIndexOf
split
toLowerCase, toUpperCase
length


Microsoft JScript Features - Non-ECMA

Microsoft® JScript™
Microsoft JScript Features
Non-ECMA 		Language Reference

Contents

Category | Feature/Keyword
Array Handling concat, slice
VBArray
dimensions, getItem, lbound, toArray, ubound
Conditional Compilation @cc_on
@if Statement
@set Statement
Conditional Compilation Variables
Control flow do...while
Labeled
switch
Dates and Time getVarDate
Enumeration Enumerator
atEnd, item, moveFirst, moveNext
Function Creation | caller
Operators Identity (===), Nonidentity (!==)
Objects Enumerator
RegExp
Regular Expression
VBArray
Regular Expressions and Pattern Matching RegExp
index, input ($_), lastIndex, lastMatch ($&), lastParen ($+), leftContext ($'), multiline ($*), rightContext ($'), $1...$9
Regular Expression
global, ignorecase, lastIndex, source
compile, exec, test
Regular Expression Syntax
Script Engine Indentification ScriptEngine
ScriptEngineBuildVersion
ScriptEngineMajorVersion
ScriptEngineMinorVersion
Strings concat, slice
match, replace, search
anchor, big, blink, bold, fixed, fontcolor, fontsize, italics, link, small, strike, sub, sup


Microsoft Scripting Run-time Object Features

Microsoft® JScript™
Microsoft Scripting Run-time Object Features 		Language Reference

Contents

Category Feature/Keyword
Collections Drives
Files
Folders
File and System Management
  • Dictionary
    Add, Exists, Items, Keys, Remove, RemoveAll
    Count, Item, Key
  • Drive, File, Folder
    Copy, Delete, Move, OpenAsTextStream
    Attributes, Count, DateCreated, DateLastAccessed, DateLastModified, Drive, ParentFolder, Name, Path, ShortName, ShortPath, Size
    AvailableSpace, DriveLetter, DriveType, FileSystem, FreeSpace, IsReady, RootFolder, SerialNumber, ShareName, TotalSize, VolumeName
  • FileSystemObject
    BuildPath, CopyFile, CopyFolder, CreateFolder, CreateTextFile, DeleteFile, DeleteFolder, DriveExists, FileExists, FolderExists, GetAbsolutePathName, GetBaseName, GetDrive, GetDriveName, GetExtensionName, GetFile, GetFileName, GetFolder, GetParentFolderName, GetSpecialFolder, GetTempName, MoveFile, MoveFolder, OpenTextFile
    Drives
  • TextStream
    Close, Read, ReadAll, ReadLine, Skip, SkipLine, Write, WriteBlankLines, WriteLine
    AtEndOfLine, AtEndOfStream, Column, Line

    • © 1997 Microsoft Corporation. All rights reserved. Terms of Use.


abs Method

Microsoft® JScript™
abs Method 		Language Reference
Version 1

See Also Applies To

Description

Determines the absolute value of its numeric argument.

Syntax
Math.abs(number)

The number argument is a numeric expression for which the absolute value is sought.

Remarks

The return value is the absolute value of the number argument.


abs Method

Microsoft® JScript™
abs Method
Applies To 		Language Reference

Math Object


abs Method

Microsoft® JScript™
abs Method
See Also 		Language Reference

Math Object Methods


acos Method

Microsoft® JScript™
acos Method 		Language Reference
Version 1

See Also Applies To

Description

Computes the arccosine of its numeric argument.

Syntax

Math.acos(number)

The number argument is a numeric expression for which the arccosine is sought.

Remarks

The return value is the arccosine of the number argument.


acos Method

Microsoft® JScript™
acos Method
Applies To 		Language Reference

Math Object


acos Method

Microsoft® JScript™
acos Method
See Also 		Language Reference

asin Method
atan Method
cos Method
Math Object Methods
sin Method
tan Method


asin Method

Microsoft® JScript™
asin Method 		Language Reference
Version 1

See Also Applies To

Description

Computes the arcsine of its numeric argument.

Syntax

Math.asin(number)

The number argument is a numeric expression for which the arcsine is sought.

Remarks

The return value is the arcsine of its numeric argument.


asin Method

Microsoft® JScript™
asin Method
Applies To 		Language Reference

Math Object


asin Method

Microsoft® JScript™
asin Method
See Also 		Language Reference

acos Method
atan Method
cos Method
Math Object Methods
sin Method
tan Method


atan Method

Microsoft® JScript™
atan Method 		Language Reference
Version 1

See Also Applies To

Description

Computes the arctangent of its numeric argument.

Syntax
Math.atan(number)

The number argument is a numeric expression for which the arctangent is sought.

Remarks

The return value is the arctangent of its numeric argument.


atan2 Method

Microsoft® JScript™
atan2 Method 		Language Reference
Version 2

See Also Applies To

Description
Returns the angle (in radians) from the X axis to a point (y,x).
Syntax
Math.atan2(y, x)

The atan2 method syntax has these parts:

Part | Description
Math | Required. Invokes the intrinsic Math object.
x | Required. A numeric expression representing the cartesian x-coordinate.
y | Required. A numeric expression representing the cartesian y-coordinate.

Remarks
The return value is between -pi and pi, representing the angle of the supplied (y,x) point.


atan2 Method

Microsoft® JScript™
atan2 Method
Applies To 		Language Reference

Math Object


atan2 Method

Microsoft® JScript™
atan2 Method
See Also 		Language Reference

atan Method
Math Object Methods
tan Method


atan Method

Microsoft® JScript™
atan Method
Applies To 		Language Reference

Math Object


atan Method

Microsoft® JScript™
atan Method
See Also 		Language Reference

acos Method
asin Method
atan2 Method
cos Method
Math Object Methods
sin Method
tan Method


ceil Method

Microsoft® JScript™
ceil Method 		Language Reference
Version 1

See Also Applies To

Description

Determines the smallest integer greater than or equal to its numeric argument.

Syntax
Math.ceil(number)

The number argument is a numeric expression.

Remarks

The return value is an integer value equal to the smallest integer greater than or equal to its numeric argument.


ceil Method

Microsoft® JScript™
ceil Method
Applies To 		Language Reference

Math Object


ceil Method

Microsoft® JScript™
ceil Method
See Also 		Language Reference

floor Method
Math Object Methods


cos Method

Microsoft® JScript™
cos Method 		Language Reference
Version 1

See Also Applies To

Description
Computes the cosine of its numeric argument.
Syntax
Math.cos(number)

The number argument is a numeric expression for which the cosine is sought.

Remarks
The return value is the cosine of its numeric argument.


cos Method

Microsoft® JScript™
cos Method
Applies To 		Language Reference

Math Object


cos Method

Microsoft® JScript™
cos Method
See Also 		Language Reference

acos Method
asin Method
atan Method
Math Object Methods
sin Method
tan Method


E Property

Microsoft® JScript™
E Property 		Language Reference
Version 1

See Also Applies To

Description
Euler's constant, the base of natural algorithms. The E property is approximately equal to 2.718.
Syntax
var numVar
numVar = Math.E


E Property

Microsoft® JScript™
E Property
Applies To 		Language Reference

Math Object


E Property

Microsoft® JScript™
E Property
See Also 		Language Reference

exp Method
Math Object Properties


exp Method

Microsoft® JScript™
exp Method 		Language Reference
Version 1

See Also Applies To

Description
Computes e to the power of the supplied numeric argument.
Syntax
Math.exp(number)

The number argument is a numeric expression representing the power of e.

Remarks
The return value is enumber. The constant e is Euler's constant, approximately equal to 2.178 and number is the supplied argument.


exp Method

Microsoft® JScript™
exp Method
Applies To 		Language Reference

Math Object


exp Method

Microsoft® JScript™
exp Method
See Also 		Language Reference

E Property
Math Object Methods


floor Method

Microsoft® JScript™
floor Method 		Language Reference
Version 1

See Also Applies To

Description
Computes the greatest integer less than or equal to its numeric argument.
Syntax
Math.floor(number)

The number argument is a numeric expression.

Remarks

The return value is an integer value equal to the greatest integer less than or equal to its numeric argument.


floor Method

Microsoft® JScript™
floor Method
Applies To 		Language Reference

Math Object


floor Method

Microsoft® JScript™
floor Method
See Also 		Language Reference

ceil Method
Math Object Methods


LN10 Property

Microsoft® JScript™
LN10 Property 		Language Reference
Version 1

See Also Applies To

Description
The natural logarithm of 10.
Syntax
var numVar
numVar = Math.LN10
Remarks
The LN10 property is approximately equal to 2.302.


LN10 Property

Microsoft® JScript™
LN10 Property
Applies To 		Language Reference

Math Object


LN10 Property

Microsoft® JScript™
LN10 Property
See Also 		Language Reference

Math Object Properties


LN2 Property

Microsoft® JScript™
LN2 Property 		Language Reference
Version 1

See Also Applies To

Description
The natural logarithm of 2.
Syntax
var numVar
numVar = Math.LN2
Syntax
The LN2 property is approximately equal to 0.693.


LN2 Property

Microsoft® JScript™
LN2 Property
Applies To 		Language Reference

Math Object


LN2 Property

Microsoft® JScript™
LN2 Property
See Also 		Language Reference

Math Object Properties


log Method

Microsoft® JScript™
log Method 		Language Reference
Version 1

See Also Applies To

Description
Computes the natural logarithm of a numeric expression.
Syntax
Math.log(number)

The number argument is a numeric expression for which the natural logarithm is sought.

Return Value

The return value is the natural logarithm of number. The base is e.


LOG10E Property

Microsoft® JScript™
LOG10E Property 		Language Reference
Version 1

See Also Applies To

Description

The base 10 logarithm of e, Euler's constant.
Syntax
var varName
varName = objName.LOG10E
Remarks

The LOG10E property, a constant, is approximately equal to 0.434.


LOG10E Property

Microsoft® JScript™
Log10E Property
Applies To 		Language Reference

Math Object


LOG10E Property

Microsoft® JScript™
LOG10E Property
See Also 		Language Reference

Math Object Properties


LOG2E Property

Microsoft® JScript™
LOG2E Property 		Language Reference
Version 1

See Also Applies To

Description
The base 2 logarithm of e, Euler's constant.
Syntax
var varName
varName = objName.LOG2E
Remarks
The LOG2E property, a constant, is approximately equal to 1.442.


LOG2E Property

Microsoft® JScript™
LOG2E Property
Applies To 		Language Reference

Math Object


LOG2E Property

Microsoft® JScript™
LOG2E Property
See Also 		Language Reference

Math Object Properties


log Method

Microsoft® JScript™
log Method
Applies To 		Language Reference

Math Object


log Method

Microsoft® JScript™
log Method
See Also 		Language Reference

Math Object Methods


max Method

Microsoft® JScript™
max Method 		Language Reference
Version 1

See Also Applies To

Description
Returns the greater of two supplied numeric expressions.
Syntax
retVal = Math.max(number1, number2)

The max method syntax has these parts:

Part | Description
retVal | The greater of number1 or number2.
number1 | A numeric expression to be compared to number2.
number2 | A numeric value to be compared to number1.


max Method

Microsoft® JScript™
max Method
Applies To 		Language Reference

Math Object


max Method

Microsoft® JScript™
max Method
See Also 		Language Reference

Math Object Methods
min Method


min Method

Microsoft® JScript™
min Method 		Language Reference
Version 1

See Also Applies To

Description
Returns the lesser of two supplied numbers.
Syntax
retVal = Math.min(number1, number2)

The min method syntax has these parts:

Part | Description
retVal | The lesser of number1 or number2.
number1 | A numeric expression to be compared to number2.
number2 | A numeric value to be compared to number1.


min Method

Microsoft® JScript™
min Method
Applies To 		Language Reference

Math Object


min Method

Microsoft® JScript™
min Method
See Also 		Language Reference

Math Object Methods
max Method


PI Property

Microsoft® JScript™
PI Property 		Language Reference
Version 1

See Also Applies To

Description
The ratio of the circumference of a circle to its diameter.
Syntax
var numVar
numVar = Math.PI
Syntax
The PI property, a constant, is approximately equal to 3.14159.


PI Property

Microsoft® JScript™
PI Property
Applies To 		Language Reference

Math Object


PI Property

Microsoft® JScript™
PI Property
See Also 		Language Reference

Math Object Properties


pow Method

Microsoft® JScript™
pow Method 		Language Reference
Version 1

See Also Applies To

Description
Returns the value of a base expression taken to a specified power.
Syntax
Math.pow(base, exponent)

The pow method syntax has these parts:

Part | Description
base | The base value of the expression.
exponent | The exponent value of the expression.

Remarks
In the following example, a numeric expression equal to baseexponent returns 1000.

Math.pow(10,3);


pow Method

Microsoft® JScript™
pow Method
Applies To 		Language Reference

Math Object


pow Method

Microsoft® JScript™
pow Method
See Also 		Language Reference

Math Object Methods


random Method

Microsoft® JScript™
random Method 		Language Reference
Version 1

See Also Applies To

Description
Returns a pseudo-random number between 0 and 1.
Syntax
Math.random( )
Remarks
The pseudo-random number generated is between 0 and 1 inclusive. The random number generator is seeded automatically when JScript is first loaded.


random Method

Microsoft® JScript™
random Method
Applies To 		Language Reference

Math Object


random Method

Microsoft® JScript™
random Method
See Also 		Language Reference

Math Object Methods


round Method

Microsoft® JScript™
round Method 		Language Reference
Version 1

See Also Applies To

Description
Rounds a supplied numeric expression to the nearest integer.
Syntax
Math.round(number)

The number argument is the value to be rounded to the nearest integer.

Remarks
If the decimal portion of number is 0.5 or greater, the return value is equal to the smallest integer greater than number. Otherwise, round returns the largest integer less than or equal to number.


round Method

Microsoft® JScript™
round Method
Applies To 		Language Reference

Math Object


round Method

Microsoft® JScript™
round Method
See Also 		Language Reference

Math Object Methods


sin Method

Microsoft® JScript™
sin Method 		Language Reference
Version 1

See Also Applies To

Description
Returns the sine of its numeric argument.
Syntax
Math.sin(number)

The number argument is a numeric expression for which the sine is sought.

Remarks
The return value is the sine of its numeric argument.


sin Method

Microsoft® JScript™
sin Method
Applies To 		Language Reference

Math Object


sin Method

Microsoft® JScript™
sin Method
See Also 		Language Reference

acos Method
asin Method
atan Method
cos Method
Math Object Methods
tan Method


sqrt Method

Microsoft® JScript™
sqrt Method 		Language Reference
Version 1

See Also Applies To

Description
Returns the square root of a number.
Syntax
Math.sqrt(number)

The number argument is a numeric expression.

Remarks
If number is negative, the return value is zero.


SQRT1_2 Property

Microsoft® JScript™
SQRT1_2 Property 		Language Reference
Version 1

See Also Applies To

Description
The square root of 0.5, or one divided by the square root of 2.
Syntax
var numVar
numVar = Math.SQRT1_2
Remarks
The SQRT1_2 property, a constant, is approximately equal to 0.707.


SQRT1_2 Property

Microsoft® JScript™
SQRT1_2 Property
Applies To 		Language Reference

Math Object


SQRT1_2 Property

Microsoft® JScript™
SQRT1_2 Property
See Also 		Language Reference

Math Object Properties
sqrt Method
SQRT2 Property


SQRT2 Property

Microsoft® JScript™
SQRT2 Property 		Language Reference
Version 1

See Also Applies To

Description
The square root of 2.
Syntax
var numVar
numVar = Math.SQRT2
Syntax
The SQRT2 property, a constant, is approximately equal to 1.414.


SQRT2 Property

Microsoft® JScript™
SQRT2 Property
Applies To 		Language Reference

Math Object


SQRT2 Property

Microsoft® JScript™
SQRT2 Property
See Also 		Language Reference

Math Object Properties
sqrt Method
SQRT1_2 Property


sqrt Method

Microsoft® JScript™
sqrt Method
Applies To 		Language Reference

Math Object


sqrt Method

Microsoft® JScript™
sqrt Method
See Also 		Language Reference

Math Object Methods
SQRT1_2 Property
SQRT2 Property


tan Method

Microsoft® JScript™
tan Method 		Language Reference
Version 1

See Also Applies To

Description

Computes the tangent of a number.
Syntax
Math.tan(number)

The number argument is a numeric expression for which the tangent is sought.

Remarks
The return value is the tangent of number.


tan Method

Microsoft® JScript™
tan Method
Applies To 		Language Reference

Math Object


tan Method

Microsoft® JScript™
tan Method
See Also 		Language Reference

acos Method
asin Method
atan Method
atan2 Method
cos Method
Math Object Methods
sin Method


MAX_VALUE Property

Microsoft® JScript™
MAX_VALUE Property 		Language Reference
Version 2

See Also Applies To

Description
The largest number representable in JScript. Equal to approximately 1.79E+308.
Syntax
Number.MAX_VALUE

The number argument is the Number object.

Remarks
The Number object does not have to be created before the MAX_VALUE property can be accessed.


MAX_VALUE Property

Microsoft® JScript™
MAX_VALUE Property
Applies To 		Language Reference

Number Object


MAX_VALUE Property

Microsoft® JScript™
MAX_VALUE Property
See Also 		Language Reference

MIN_VALUE Property
NaN Property
NEGATIVE_INFINITY Property
POSITIVE_INFINITY Property
toString Method


MAX_VALUE Property

Microsoft® JScript™
MIN_VALUE Property 		Language Reference
Version 2

See Also Applies To

Description
The number closest to zero representable in JScript. Equal to approximately 2.22E-308.
Syntax
Number.MIN_VALUE

The number argument is the Number object.

Remarks
The Number object does not have to be created before the MIN_VALUE property can be accessed.


MIN_VALUE Property

Microsoft® JScript™
MIN_VALUE Property
Applies To 		Language Reference

Number Object


MIN_VALUE Property

Microsoft® JScript™
MIN_VALUE Property
See Also 		Language Reference

MAX_VALUE Property
NaN Property
NEGATIVE_INFINITY Property
POSITIVE_INFINITY Property
toString Method


NaN Property

Microsoft® JScript™
NaN Property 		Language Reference
Version 2

See Also Applies To

Description
A special value that indicates an arithmetic expression returned a value that was not a number.
Syntax
Number.NaN

The number argument is the Number object.

Remarks
The Number object does not have to be created before the NaN property can be accessed.

NaN does not compare equal to any value, including itself. To test if a value is equivalent to NaN, use the isNaN function.


NaN Property

Microsoft® JScript™
NaN Property
Applies To 		Language Reference

Number Object


NaN Property

Microsoft® JScript™
NaN Property
See Also 		Language Reference

isNaN Method
MAX_VALUE Property
MIN_VALUE Property
NEGATIVE_INFINITY Property
POSITIVE_INFINITY Property
toString Method


NEGATIVE_INFINITY Property

Microsoft® JScript™
NEGATIVE_INFINITY Property 		Language Reference
Version 2

See Also Applies To

Description
A value more negative than the largest negative number (-Number.MAX_VALUE) representable in JScript.
Syntax
Number.NEGATIVE_INFINITY

The number argument is the Number object.

Remarks
The Number object does not have to be created before the NEGATIVE_INFINITY property can be accessed.

JScript displays NEGATIVE_INFINITY values as -Infinity. This value behaves mathematically as infinity.


NEGATIVE_INFINITY Property

Microsoft® JScript™
NEGATIVE_INFINITY Property
Applies To 		Language Reference

Number Object


NEGATIVE_INFINITY Property

Microsoft® JScript™
NEGATIVE_INFINITY Property
See Also 		Language Reference

MAX_VALUE Property
MIN_VALUE Property
NaN Property
POSITIVE_INFINITY Property
toString Method


POSITIVE_INFINITY Property

Microsoft® JScript™
POSITIVE_INFINITY Property 		Language Reference
Version 2

See Also Applies To

Description
A value larger than the largest number (Number.MAX_VALUE) representable in JScript.
Syntax
Number.POSITIVE_INFINITY

The number argument is the Number object.

Remarks
The Number object does not have to be created before the POSITIVE_INFINITY property can be accessed.

JScript displays POSITIVE_INFINITY values as Infinity. This value behaves mathematically as infinity.


POSITIVE_INFINITY Property

Microsoft® JScript™
POSITIVE_INFINITY Property
Applies To 		Language Reference

Number Object


POSITIVE_INFINITY Property

Microsoft® JScript™
POSITIVE_INFINITY Property
See Also 		Language Reference

MAX_VALUE Property
MIN_VALUE Property
NaN Property
NEGATIVE_INFINITY Property
toString Method


toString Method (Number)

Microsoft® JScript™
toString Method (Number) 		Language Reference
Version 2

See Also Applies To

Description
Converts a Number object or numeric variable into a string using the specified radix.
Syntax
number.toString([ radix ]);

The toString method syntax has these parts:

Part | Description
number | A Number object or variable. Cannot be a numeric literal.
radix | An optional argument specifying the base to use when converting the number. Values between 2 and 16 inclusive are accepted. If not supplied, base 10 is used.

Remarks
Due to syntax restrictions, the toString method cannot be used on numeric literals. Values must be assigned to variables first. For example, the following code is invalid:

str = 1997.toString( );
This code must be rewritten:

var yr = 1997;
str = yr.toString( );


toString Method (Number)

Microsoft® JScript™
toString Method (Number)
Applies To 		Language Reference

Number Object


toString Method (Number)

Microsoft® JScript™
toString Method (Number)
See Also 		Language Reference

MAX_VALUE Property
MIN_VALUE Property
NaN Property
NEGATIVE_INFINITY Property
POSITIVE_INFINITY Property
toString Method (Function)


ActiveXObject Object

Microsoft® JScript™
ActiveXObject Object 		Language Reference
Version 3

See Also

Description
Enables and returns a reference to an Automation object.
Syntax
var newObject = new ActiveXObject(class)

The class argument uses the syntax servername.typename and has these parts:

Part | Description
servername | The name of the application providing the object.
typename | The type or class of the object to create.

Remarks
Automation servers provide at least one type of object. For example, a word-processing application may provide an application object, a document object, and a toolbar object.

To create an Automation object, assign the new ActiveXObject to an object variable:

var ExcelSheet;
ExcelSheet = new ActiveXObject("Excel.Sheet");
This code starts the application creating the object (in this case, a Microsoft Excel worksheet). Once an object is created, you refer to it in code using the object variable you defined. In the following example, you access properties and methods of the new object using the object variable, ExcelSheet, and other Excel objects, including the Application object and the ActiveSheet.Cells collection. For example:

// Make Excel visible through the Application object.
ExcelSheet.Application.Visible = true;
// Place some text in the first cell of the sheet.
ExcelSheet.ActiveSheet.Cells(1,1).Value = "This is column A, row 1";
// Save the sheet.
ExcelSheet.SaveAs("C:\TEST.XLS");
// Close Excel with the Quit method on the Application object.
ExcelSheet.Application.Quit();
// Release the object variable.
ExcelSheet = "";


ActiveXObject Object

Microsoft® JScript™
ActiveXObject Object
See Also 		Language Reference

GetObject Function


Array Object

Microsoft® JScript™
Array Object
Language Reference
Version 2

See Also Methods Properties

Description
Provides support for creation of arrays of any data type.
Syntax
new Array()
new Array(size)
new Array(element0, element1, ..., elementn)

The Array object creation syntax has these parts:

Part | Description
size | The size of the array. As arrays are zero-based, created elements will have indices from zero to size - 1.
element0,...,elementn | The elements to place in the array. This creates an array with n + 1 elements, and a length of n.

Remarks
After an array is created, the individual elements of the array can be accessed using [ ] notation, for example:

var my_array = new Array();
for (i = 0; i < 10; i++)
    {
    my_array[i] = i;
    }
x = my_array[4];
Since arrays in Microsoft JScript are zero-based, the last statement in the preceding example accesses the fifth element of the array. That element contains the value 4.

If only one argument is passed to the Array constructor, and it is a number, it is coerced into an unsigned integer and the value is used as the size of the array. Otherwise, the parameter passed in is used as the only element of the array.


Array Object

Microsoft® JScript™
Array Object
See Also 		Language Reference

new Operator


Array Object Methods

Microsoft® JScript™
Array Object
Methods 		Language Reference

Members of Array.prototype
concat Method
join Method
reverse Method
slice Method
sort Method

Object.toString Method
Object.valueOf Method
Nonmembers of Array.prototype
Array has no methods that are not part of the prototype.


Array Object Properties

Microsoft® JScript™
Array Object
Properties 		Language Reference

Members of Array.prototype
Object.constructor Property
Nonmembers of Array.prototype
length Property
prototype Property


Boolean Object

Microsoft® JScript™
Boolean Object 		Language Reference
Version 2

See Also Methods Properties

Description
Creates a new Boolean value.
Syntax
var variablename = new Boolean(boolvalue)

The optional boolvalue argument is the initital Boolean value for the new object. If this value is omitted, or is false, 0, null, NaN, or an empty string, the initial value of the Boolean object is false. Otherwise, the initial value is true.

Remarks
The Boolean object is a wrapper for the Boolean data type. JScript implicitly uses the Boolean object whenever a Boolean data type is converted to a Boolean object.

You rarely call the Boolean object explicitly.


Boolean Object

Microsoft® JScript™
Boolean Object
See Also 		Language Reference

new Operator
var Statement


Boolean Object Methods

Microsoft® JScript™
Boolean Object
Methods 		Language Reference

Members of Boolean.prototype
Object.toString Method
Object.valueOf Method
Nonmembers of Boolean.prototype
Boolean has no methods that are not part of the prototype.


Boolean Object Properties

Microsoft® JScript™
Boolean Object
Properties 		Language Reference

Members of Boolean.prototype
Object.constructor Property
Nonmembers of Boolean.prototype
prototype Property


Date Object

Microsoft® JScript™
Date Object 		Language Reference
Version 1

See Also Methods Properties

Description
Enables basic storage and retrieval of dates and times.
Syntax
var newDateObj = new Date()
var newDateObj = new Date(dateVal)
var newDateObj = new Date(year, month, date[, hours[, minutes[, seconds[,ms]]]])

The Date object constructor syntax has these parts:

Part | Description
dateVal | If a numeric value, dateVal represents the number of milliseconds in Universal Coordinated Time between the specified date and midnight January 1, 1970. If a string, dateVal is parsed according to the rules in the parse method. The dateVal argument can also be a VT_DATE value as returned from some ActiveX objects.
year | Required. The full year, for example, 1976 (and not 76).
month | Required. The month as an integer between 0 and 11 (January to December).
date | Required. The date as an integer between 1 and 31.
hours | Optional. Must be supplied if minutes is supplied. An integer from 0 to 23 (midnight to 11pm) that specifies the hour.
minutes | Optional. Must be supplied if seconds is supplied. An integer from 0 to 59 that specifies the minutes.
seconds | Optional. Must be supplied if milliseconds is supplied. An integer from 0 to 59 that specifies the seconds.
ms | Optional. An integer from 0 to 999 that specifies the milliseconds.

Remarks
A Date object contains a number representing a particular instant in time to within a millisecond. If the value of an argument is greater than its range or is a negative number, other stored values are modified accordingly. For example, if you specify 150 seconds, JScript redefines that number as two minutes and 30 seconds.

If the number is NaN, that indicates that the object does not represent a specific instant of time. If you pass no parameters to the Date object, it is initialized to the current time (UTC). A value must be given to the object before you can use it.

The range of dates that can be represented in a Date object is approximately 285,616 years on either side of January 1, 1970.

The Date object has two static methods that are called without creating a Date object. They are parse and UTC.


Date Object

Microsoft® JScript™
Date Object
See Also 		Language Reference

new Operator
var Statement


Date Object Methods

Microsoft® JScript™
Date Object
Methods 		Language Reference

Members of Date.prototype
getDate Method
getDay Method
getFullYear Method
getHours Method
getMilliseconds Method
getMinutes Method
getMonth Method
getSeconds Method
getTime Method
getTimezoneOffset Method
getUTCDate Method
getUTCDay Method
getUTCFullYear Method
getUTCHours Method
getUTCMilliSeconds Method
getUTCMinutes Method
getUTCMonth Method
getUTCSeconds Method
getVarDate Method
getYear Method
setDate Method
setFullYear Method
setHours Method
setMilliSeconds Method
setMinutes Method
setMonth Method
setSeconds Method
setTime Method
setUTCDate Method
setUTCFullYear Method
setUTCHours Method
setUTCMilliseconds Method
setUTCMinutes Method
setUTCMonth Method
setUTCSeconds Method
setYear Method
toGMTString Method
toLocaleString Method
toUTCString Method

Object.toString Method
Object.valueOf Method
Nonmembers of Date.prototype
parse Method
UTC Method


Date Object Properties

Microsoft® JScript™
Date Object
Properties 		Language Reference

constructor Property
prototype Property


Dictionary Object

Microsoft® JScript™
Dictionary Object 		Language Reference
Version 2

See Also Methods Properties

Description
Object that stores data key, item pairs.

Syntax
y = new ActiveXObject("Scripting.Dictionary")
Remarks
A Dictionary object is the equivalent of a PERL associative array. Items, which can be any form of data, are stored in the array. Each item is associated with a unique key. The key is used to retrieve an individual item and is usually a integer or a string, but can be anything except an array.

The following code illustrates how to create a Dictionary object:

var y = new ActiveXObject("Scripting.Dictionary");
y.add ("a", "test");
if (y.Exists("a"))
  document.write("true");
...


Dictionary Object

Microsoft® JScript™
Dictionary Object
See Also 		Language Reference

FileSystemObject Object
TextStream Object


Dictionary Object Methods

Microsoft® JScript™
Dictionary Object
Methods 		Language Reference

Add Method
Exists Method
Items Method
Keys Method
Remove Method
RemoveAll Method


Dictionary Object Properties

Microsoft® JScript™
Dictionary Object
Properties 		Language Reference

Count Property
Item Property
Key Property


Drive Object

Microsoft® JScript™
Drive Object 		Language Reference
Version 3

See Also Properties Methods

Description
Provides access to the properties of a particular disk drive or network share.
Remarks
The following code illustrates the use of the Drive object to access drive properties:
function ShowFreeSpace(drvPath)
{
    var fs, d, s;
    fs = new ActiveXObject("Scripting.FileSystemObject");
    d = fs.GetDrive(fs.GetDriveName(drvPath));
    s = "Drive " + drvPath + " - " ;
    s += d.VolumeName + "<br>";
    s += "Free Space: " + d.FreeSpace/1024 + " Kbytes";
    Response.Write(s);
}


Drive Object

Microsoft® JScript™
Drive Object
See Also 		Language Reference

Drives Collection
File Object
Files Collection
Folder Object
Folders Collection
GetDrive Method


Drive Object

Microsoft® JScript™
Drive Object
Methods 		Language Reference

The Drive object has no methods.


Drive Object

Microsoft® JScript™
Drive Object
Properties 		Language Reference

AvailableSpace Property
DriveLetter Property
DriveType Property
FileSystem Property
FreeSpace Property
IsReady Property
Path Property
RootFolder Property
SerialNumber Property
ShareName Property
TotalSize Property
VolumeName Property


constructor Property

Microsoft® JScript™
constructor Property 		Language Reference
Version 2

See Also Applies To

Description

Specifies the function that creates an object.

Syntax

object.constructor

The required object argument is the name of an object or function.

Remarks
The constructor property is a member of the prototype of every object that has a prototype. This includes all intrinsic JScript objects except the Global and Math objects. The constructor property contains a reference to the function that constructs instances of that particular object. For example:
x = new String("Hi");
if (x.constructor == String)
   //  Do something (the condition will be true).
or
function MyFunc {
// Body of function.
}

y = new MyFunc;
if (y.constructor == MyFunc)
   //  Do something (the condition will be true).


constructor Property

Microsoft® JScript™
constructor Property
Applies To 		Language Reference

Array Object
Boolean Object
Date Object
Function Object
Math Object
Number Object
Object Object
String Object


constructor Property

Microsoft® JScript™
constructor Property
See Also 		Language Reference

prototype Property


prototype Property

Microsoft® JScript™
prototype Property 		Language Reference
Version 2

See Also Applies To

Description
Contains a reference to the prototype for a class of objects.
Syntax
objectname.prototype

The objectname argument is the name of an object.

Remarks
Use the prototype property to provide a base set of functionality to a class of objects. New instances of an object "inherit" the behavior of the prototype assigned to that object.

For example, say you wanted to add a method to the Array object that returns the value of the largest element of the array. To do this, declare the function, add it to Array.prototype, and then use it.

function array_max( )
{
  var i, max = this[0];
  for (i = 1; i < this.length; i++)
  {
     if (max < this[i])
         max = this[i];
  }
  return max;
}
Array.prototype.max = array_max;
var x = new Array(1, 2, 3, 4, 5, 6);
var y = x.max( );
After this code is executed, y contains the largest value in the array x, or 6.

All intrinsic JScript objects have a prototype property that is read-only. Functionality may be added to the prototype, as in the example, but the object may not be assigned a different prototype.

This is not the case for user-defined objects: User-defined objects may be assigned a new prototype.

The method and property lists for each intrinsic object in this language reference indicate which ones are part of the object's prototype, and which are not.


prototype Property

Microsoft® JScript™
prototype Property
Applies To 		Language Reference

Array Object
Boolean Object
Date Object
Function Object
Number Object
Object Object
String Object


prototype Property

Microsoft® JScript™
prototype Property
See Also 		Language Reference

constructor Property


toString Method

Microsoft® JScript™
toString Method 		Language Reference
Version 2

See Also Applies To

Description
Returns a string representation of an object.
Syntax
objectname.toString( )

The objectname argument is an object for which a string representation is sought.

Remarks
The toString method is a member of all built-in JScript objects. How it behaves depends on the object type:

Object | Behavior
Array | Behavior [still to come]
Boolean | If the Boolean value is true, returns "true". Otherwise, returns "false"
Function Returns a string returned of the following form, where functionname is the name of the function whose toString method was called:
function functionname( ) { [native code] }
Number | Returns the textual representation of the number.
String | Returns the value of the String object.
Default | Returns "[object objectname]", where objectname is the name of the object type.


toString Method

Microsoft® JScript™
toString Method
Applies To 		Language Reference

Array Object
Boolean Object
Function Object
Number Object
String Object


toString Method

Microsoft® JScript™
toString Method
See Also 		Language Reference

function Statement


valueOf Method

Microsoft® JScript™
valueOf Method 		Language Reference
Version 2

See Also Applies To

Description
Returns the primitive value of the specified object.
Syntax
object.valueOf( )

The object argument is any JScript object.

Remarks
The valueOf method is defined differently for each intrinsic JScript object.

Object | Return Value
Array | The elements of the array are converted into strings, and the strings are concatenated together, separated by commas. This behaves the same as the Array.toString and Array.join methods.
Boolean | The Boolean value.
Date | The stored time value in milliseconds since midnight, January 1, 1970 UTC.
Function | The function itself.
Number | The numeric value.
Object | The object itself. This is the default.
String | The string value.

The Math object does not have a valueOf property.


valueOf Method

Microsoft® JScript™
valueOf Method
Applies To 		Language Reference

Array Object
Boolean Object
Date Object
Function Object
Number Object
Object Object
String Object


valueOf Method

Microsoft® JScript™
valueOf Method
See Also 		Language Reference

toString Method


Enumerator Object

Microsoft® JScript™
Enumerator Object 		Language Reference
Version 3

See Also Methods Properties

Description
Provides a way to enumerate items in a collection.
Syntax
new Enumerator(collection)

The collection argument is any collection object.

Remarks
Collections differ from arrays in that the members of a collection are not directly accessible. Instead of using indices, as you would with arrays, you can only move the current item pointer to the first or next element of a collection.

The Enumerator object provides a way to access any member of a collection and behaves similarly to the For...Each statement in VBScript.

The following code shows the usage of the Enumerator object:

function ShowDriveList()
{
    var fs, s, n, e, x;
    fs = new ActiveXObject("Scripting.FileSystemObject");
    e = new Enumerator(fs.Drives);
    s = "";
    for (;!e.atEnd();e.moveNext())
    {
        x = e.item();
        s = s + x.DriveLetter;
        s += " - ";
        if (x.DriveType == 3)
             n = x.ShareName;
        else if (x.IsReady)
             n = x.VolumeName;
        else
             n = "[Drive not ready]";
        s +=  n + "<br>";
    }
    Response.Write(s);
}


Enumerator Object

Microsoft® JScript™
Enumerator Object
See Also 		Language Reference

Drives Collection
Files Collection
Folders Collection


Enumerator Object

Microsoft® JScript™
Enumerator Object
Methods 		Language Reference

atEnd Method
item Method
moveFirst Method
moveNext Method


Enumerator Object

Microsoft® JScript™
Enumerator Object
Properties 		Language Reference

The Enumerator object has no properties.


File Object

Microsoft® JScript™
File Object 		Language Reference
Version 3

See Also Properties Methods

Description
Provides access to all the properties of a file.
Remarks
The following code illustrates how to obtain a File object and how to view one of its properties.
function ShowFileInfo(filespec)
{
    var fs, file, s;
    fs = new ActiveXObject("Scripting.FileSystemObject");
    file = fs.GetFile(filespec);
    s = file.DateCreated;
    Response.Write(s);
}


File Object

Microsoft® JScript™
File Object
See Also 		Language Reference

Drive Object
Drives Collection
Files Collection
Folder Object
Folders Collection


File Object

Microsoft® JScript™
File Object
Methods 		Language Reference

Copy Method
Delete Method
Move Method
OpenAsTextStream Method


File Object

Microsoft® JScript™
File Object
Properties 		Language Reference

Attributes Property
DateCreated Property
DateLastAccessed Property
DateLastModified Property
Drive Property
Name Property
ParentFolder Property
Path Property
ShortName Property
ShortPath Property
Size Property
Type Property


FileSystemObject Object

Microsoft® JScript™
FileSystemObject Object 		Language Reference
Version 2

See Also Methods Properties

Description
Provides access to a computer's file system.
Syntax
y = new ActiveXObject("Scripting.FileSystemObject")
Remarks
The following code illustrates how the FileSystemObject is used to return a TextStream object that can be read from or written to:
var fs = new ActiveXObject("Scripting.FileSystemObject");
var a = fs.CreateTextFile("c:\testfile.txt", true);
a.WriteLine("This is a test.");
a.Close();
In the example code, the ActiveXObject object is assigned to the FileSystemObject (fs). The CreateTextFile method then creates the file as a TextStream object (a) and the WriteLine method writes a line of text to the created text file. The Close method flushes the buffer and closes the file.


FileSystemObject Object

Microsoft® JScript™
FileSystemObject Object
See Also 		Language Reference

Dictionary Object
Drive Object
Drives Collection
File Object
Files Collection
Folder Object
Folders Collection
TextStream Object


FileSystemObject Object Methods

Microsoft® JScript™
FileSystemObject Object
Methods 		Language Reference

BuildPath Method
CopyFile Method
CopyFolder Method
CreateFolder Method
CreateTextFile Method
DeleteFile Method
DeleteFolder Method
DriveExists Method
FileExists Method
FolderExists Method
GetAbsolutePathName Method
GetBaseName Method
GetDrive Method
GetDriveName Method
GetExtensionName Method
GetFile Method
GetFileName Method
GetFolder Method
GetParentFolderName Method
GetSpecialFolder Method
GetTempName Method
MoveFile Method
MoveFolder Method
OpenTextFile Method


FileSystemObject Object Properties

Microsoft® JScript™
FileSystemObject Object
Properties 		Language Reference

Drives Property


Folder Object

Microsoft® JScript™
Folder Object 		Language Reference
Version 3

See Also Properties Methods

Description
Provides access to all the properties of a folder.
Remarks
The following code illustrates how to obtain a Folder object and how to return one of its properties:
function ShowFolderInfo(folderspec)
{
    var fs, folder, s;
    fs = new ActiveXObject("Scripting.FileSystemObject");
    folder = fs.GetFolder(folderspec);
    s = folder.DateCreated;
    Response.Write(s);
}


Folder Object

Microsoft® JScript™
Folder Object
See Also 		Language Reference

Drive Object
Drives Collection
File Object
Files Collection
Folders Collection


Folder Object

Microsoft® JScript™
Folder Object
Methods 		Language Reference

Copy Method
Delete Method
Move Method
OpenAsTextStream Method


Folder Object

Microsoft® JScript™
Folder Object
Properties 		Language Reference

Attributes Property
DateCreated Property
DateLastAccessed Property
DateLastModified Property
Drive Property
IsRootFolder Property
Name Property
ParentFolder Property
Path Property
ShortName Property
ShortPath Property
Size Property
SubFolders Property


Function Object

Microsoft® JScript™
Function Object 		Language Reference
Version 2

See Also Methods Properties

Description
Creates a new function.
Syntax 1
function functionname( [argname1 [, ... argnameN]] )
{
body
}
Syntax 2
var functionname = new Function( [argname1, [... argnameN,]] body );

The Function object syntax has these parts:

Part | Description
functionname | The name of the newly created function
argname1...argnameN | An optional list of arguments that the function accepts.
body | A string that contains the block of JScript code to be executed when the function is called.

Remarks
Syntax 1 is the standard way to create new functions in JScript. Syntax 2 is an alternative form used to create function objects explicitly.

The function is a basic data type in JScript. Syntax 1 creates a function value that JScript converts into a Function object when necessary. JScript converts Function objects created by Syntax 2 into function values at the time the function is called.

For example, if you want to create a function that adds the two arguments passed to it, you can do it in either of two ways:

Example 1
function add(x, y)
{
   return x + y;
}
Example 2
var add = new Function("x", "y", "return x+y");
In either case, you call the function with a line of code similar to the following:
add(2, 3);


Function Object

Microsoft® JScript™
Function Object
See Also 		Language Reference

function Statement
new Operator
var Statement


Function Object Methods

Microsoft® JScript™
Function Object
Methods 		Language Reference

Members of Function.prototype
Object.toString Method
Object.valueOf Method
Nonmembers of Function.prototype
Function has no methods that are not part of the prototype.


Function Object Properties

Microsoft® JScript™
Function Object
Properties 		Language Reference

Members of Function.prototype
arguments Property
caller Property

Object.constructor Property
Nonmembers of Function.prototype
prototype Property


Global Object

Microsoft® JScript™
Global Object 		Language Reference
Version 3

See Also Methods Properties

Description
An intrinsic object whose purpose is to collect global methods into one object.
Syntax
The Global object has no syntax. You call its methods directly.
Remarks
The Global object is never used directly, and cannot be created using the new operator. It is created when the scripting engine is initialized, thus making its methods and properties available immediately.


Global Object

Microsoft® JScript™
Global Object
See Also 		Language Reference

Object Object


Global Object

Microsoft® JScript™
Global Object
Methods 		Language Reference

escape Method
eval Method
isFinite Method
isNaN Method
parseFloat Method
parseInt Method
unescape Method


Global Object

Microsoft® JScript™
Global Object
Properties 		Language Reference

NaN Property
Infinity Property


Math Object

Microsoft® JScript™
Math Object 		Language Reference
Version 1

See Also Methods Properties

Description
A built-in object that provides basic mathematics functionality and constants.
Syntax
Math[.{property | method}]
Remarks
The Math object cannot be created using the new operator, and gives an error if you attempt to do so. It is created by the scripting engine when the engine is loaded. All of its methods and properties are available to your script at all times.


Math Object

Microsoft® JScript™
Math Object
See Also 		Language Reference

Number Object


Math Object Methods

Microsoft® JScript™
Math Object
Methods 		Language Reference

Members of Math.prototype
Math has no methods that are part of the prototype.

Nonmembers of Math.prototype
abs Method
acos Method
asin Method
atan Method
atan2 Method
ceil Method
cos Method
exp Method
floor Method
log Method
max Method
min Method
pow Method
random Method
round Method
sin Method
sqrt Method
tan Method


Math Object Properties

Microsoft® JScript™
Math Object
Properties 		Language Reference

E Property
LN2 Property
LN10 Property
LOG2E Property
LOG10E Property
PI Property
SQRT1_2 Property
SQRT2 Property


Number Object

Microsoft® JScript™
Number Object 		Language Reference
Version 2

See Also Methods Properties

Description
An object representation of the number data type and placeholder for numeric constants.
Syntax
new Number( value )

The value argument is the sought numerical value for the object.

Remarks
JScript creates Number objects as required from numerical values. It is rarely necessary to create Number objects explicitly.

The primary purposes for the Number object are to collect its properties into one object, and to allow numbers to be converted into strings via the toString method.


Number Object

Microsoft® JScript™
Number Object
See Also 		Language Reference

Math Object
new Operator


Number Object Methods

Microsoft® JScript™
Number Object
Methods 		Language Reference

Members of Number.prototype
Object.toString Method
Object.valueOf Method
Nonmembers of Number.prototype
Number has no methods that are not part of the prototype.


Number Object Properties

Microsoft® JScript™
Number Object
Properties 		Language Reference

Members of Number.prototype
MAX_VALUE Property
MIN_VALUE Property
NaN Property
NEGATIVE_INFINITY Property
POSITIVE_INFINITY Property

Object.constructor Property
Nonmembers of Number.prototype
prototype Property


Object Object

Microsoft® JScript™
Object Object 		Language Reference
Version 3

See Also Methods Properties

Description
Provides functionality common to all JScript objects.
Syntax
new Object([value])

The optional value argument is used if you want to convert a primitive data type (number, Boolean, string, or function) into an object. If omitted, an object with no contents is created.

Remarks
The Object object is contained in all other JScript objects--all of its methods and properties are available in all other objects. The methods can be redefined in objects you define, and are called by JScript at appropriate times. The toString method is an example of a frequently redefined Object method.

In this language reference, the description of each Object method includes both default and object-specific implementation information for the intrinsic JScript objects.


Object Object

Microsoft® JScript™
Object Object
See Also 		Language Reference

Function Object
Global Object


Object Object

Microsoft® JScript™
Object Object
Methods 		Language Reference

Members of Object.prototype
toString Method
valueOf Method

Non-members of Object.prototype
Object has no methods that are not part of the prototype.


Object Object

Microsoft® JScript™
Object Object
Properties 		Language Reference

Members of Object.prototype
prototype property
constructor property

Non-members of Object.prototype
Object has no properties that are not part of the prototype.


RegExp Object

Microsoft® JScript™
RegExp Object 		Language Reference
Version 3

See Also Methods Properties

Description
Stores information on regular expression pattern searches.
Syntax
RegExp.propertyname

The propertyname argument is one of the RegExp object properties.

Remarks
The RegExp object cannot be created directly, but is always available for use. Its properties have undefined as their value until a successful regular expression search has been completed.


RegExp Object

Microsoft® JScript™
RegExp Object
See Also 		Language Reference

Regular Expression Object
Regular Expression Syntax
String Object


RegExp Object

Microsoft® JScript™
RegExp Object
Methods 		Language Reference

The RegExp object has no methods.


RegExp Object

Microsoft® JScript™
RegExp Object
Properties 		Language Reference

$1...$9 Properties
index Property
input Property
lastIndex Property
lastMatch Property
lastParen Property
leftContext Property
multiline Property
rightContext Property


Regular Expression Object

Microsoft® JScript™
Regular Expression Object 		Language Reference
Version 3

See Also Methods Properties

Description
Contains a regular expression pattern.
Syntax 1
var regularexpression = /pattern/[switch]
Syntax 2
var regularexpression = new RegExp("pattern",["switch"])

The regular expression object syntax has these parts:

Part | Description
pattern | Required. The regular expression pattern to use. If you use Syntax 1, delimit the pattern by "/" characters. If you use Syntax 2, enclose the pattern in quotes.
switch Optional. Enclose switch in quotes if you use Syntax 2. Available switches are:
  • i (ignore case)
  • g (global search for all occurrences of pattern)
  • gi (global search, ignore case)

    • Remarks
    Regular Expression objects store patterns used when searching strings for character combinations. After the Regular Expression object is created, it is either passed to a string method, or a string is passed to one of the regular expression methods. Information about the most recent search performed is stored in the RegExp object.

    Use Syntax 1 when you know the search string ahead of time. Use Syntax 2 when the search string is changing frequently, or is unknown, such as strings taken from user input.

    The pattern argument is compiled into an internal format before use. For Syntax 1, pattern is compiled as the script is loaded. For Syntax 2, pattern is compiled just before use, or when the compile method is called.


Regular Expression Object

Microsoft® JScript™
Regular Expression Object
See Also 		Language Reference

RegExp Object
Regular Expression Syntax
String Object


Regular Expression Object

Microsoft® JScript™
Regular Expression Object
Methods 		Language Reference

compile Method
exec Method
test Method


Regular Expression Object

Microsoft® JScript™
Regular Expression Object
Properties 		Language Reference

global Property
ignoreCase Property
lastIndex Property
source Property


String Object

Microsoft® JScript™
String Object 		Language Reference
Version 1

See Also Methods Properties

Description
Allows manipulation and formatting of text strings and determination and location of substrings within strings.
Syntax
StringObj[.method]
"String Literal"[.method]
Remarks
String objects can be created implicitly using string literals. String objects created in this fashion (referred to as standard strings) are treated differently than String objects created using the new operator. All string literals share a common, global string object. So, if a property is added to a string literal, it is available to all standard string objects:
var alpha, beta;
alpha = "This is a string";
beta = "This is also a string";

alpha.test = 10;

In this example, test is now defined for beta and all future string literals. In the following example, however, added properties are treated differently:

var gamma, delta;
gamma = new String("This is a string");
delta = new String("This is also a string");

gamma.test = 10;

In this case, test is not defined for delta. Each String object declared as a new String object has its own set of members. This is the only case where String objects and string literals are handled differently.


String Object

Microsoft® JScript™
String Object
See Also 		Language Reference

new Operator


String Object Methods

Microsoft® JScript™
String Object
Methods 		Language Reference

Members of String.prototype
anchor Method
big Method
blink Method
bold Method
charAt Method
charCodeAt Method
concat Method
fixed Method
fontcolor Method
fontsize Method
fromCharCode Method
indexOf Method
italics Method
lastIndexOf Method
link Method
match Method
replace Method
search Method
slice Method
small Method
split Method
strike Method
sub Method
substr Method
substring Method
sup Method
toLowerCase Method
toUpperCase Method

Object.toString Method
Object.valueOf Method
Nonmembers of String.prototype
String has no methods that are not part of the prototype.


String Object Properties

Microsoft® JScript™
String Object
Properties 		Language Reference

Members of String.prototype
Object.constructor Property
Nonmembers of String.prototype
length Property
prototype Property


TextStream Object

Microsoft® JScript™
TextStream Object 		Language Reference
Version 2

See Also Methods Properties

Description
Facilitates sequential access to file.
Syntax
TextStream.{property | method( )}

The property and method arguments can be any of the properties and methods associated with the TextStream object. Note that in actual usage TextStream is replaced by a variable placeholder representing the TextStream object returned from the FileSystemObject.

Remarks
In the following code, a is the TextStream object returned by the CreateTextFile method on the FileSystemObject:
var fs = new ActiveXObject("Scripting.FileSystemObject")
var a = fs.CreateTextFile("c:\\testfile.txt", true)
a.WriteLine("This is a test.")
a.Close
WriteLine and Close are two methods of the TextStream object.


TextStream Object

Microsoft® JScript™
TextStream Object
See Also 		Language Reference

Dictionary Object
FileSystemObject Object


TextStream Object Methods

Microsoft® JScript™
TextStream Object
Methods 		Language Reference

Close Method
Read Method
ReadAll Method
ReadLine Method
Skip Method
SkipLine Method
Write Method
WriteBlankLines Method
WriteLine Method


TextStream Object Properties

Microsoft® JScript™
TextStream Object
Properties 		Language Reference

AtEndOfLine Property
AtEndOfStream Property
Column Property
Line Property


VBArray Object

Microsoft® JScript™
VBArray Object 		Language Reference
Version 3

See Also Methods Properties

Description
Provides access to Visual Basic safe arrays.
Syntax
new VBArray(safeArray)

The safeArray is a VBArray value.

Remarks
VBArrays are read-only, and cannot be created directly. The safeArray argument must have obtained a VBArray value before being passed to the VBArray constructor. This can only be done by retrieving the value from an existing ActiveX or other object.

VBArrays can have multiple dimensions. The indices of each dimension can be different. The dimensions method retrieves the number of dimensions in the array; the lbound and ubound methods retrieve the range of indices used by each dimension.


VBArray Object

Microsoft® JScript™
VBArray Object
See Also 		Language Reference

Array Object


VBArray Object

Microsoft® JScript™
VBArray Object
Methods 		Language Reference

dimensions Method
getItem Method
lbound Method
toArray Method
ubound Method


VBArray Object

Microsoft® JScript™
VBArray Object
Properties 		Language Reference

The VBArray object has no properties.


Operator Precedence

Microsoft® JScript™
Operator Precedence 		Language Reference
Version 1

Operators in JScript are evaluated in a particular order. This order is known as the operator precedence. The following table lists the operators in highest to lowest precedence order. Operators with the same precedence are evaluated in left to right order in the expression.

Operator | Description
. [] () Field access, array indexing, and function calls
++ -- - ~ ! delete new typeof void | Unary operators, return data type, object creation, undefined values
* / % Multiplication, division, modulo division
+ - + Addition, subtraction, string concatenation
<< >> >>> Bit shifting
< <= > >= Less than, less than or equal, greater than, greater than or equal
== != === !== Equality, inequality, identity, nonidentity
& Bitwise AND
^ Bitwise XOR
| Bitwise OR
&& Logical AND
|| Logical OR
?: Conditional
= OP= | Assignment, assignment with operation
, Multiple evaluation

Parentheses are used to alter the order of evaluation. The expression within parentheses is fully evaluated before its value is used in the remainder of the statement.

An operator with higher precedence is evaluated before one with lower precedence. For example:

z = 78 * (96 + 3 + 45)

There are five operators in this expression: =, *, (), +, and +. According to precedence, they are evaluated in the following order: (), *, +, +, =.

  1. Evaluation of the expression within the parentheses is first: There are two addition operators, and they have the same precedence: 96 and 3 are added together and 45 is added to that total, resulting in a value of 144.
  2. Multiplication is next: 78 and 144 are multiplied, resulting in a value of 10998.
  3. Assignment is last: 11232 is assigned into z.


JScript Operators

Microsoft® JScript™
JScript Operators 		JScript Tutorial
Previous
Next

JScript has a full range of operators, including arithmetic, logical, bitwise, and assignment operators. There are also a few miscellaneous operators.

Computational | Logical | Bitwise | Assignment | Miscellaneous
Description | Symbol | Description | Symbol | Description | Symbol | Description | Symbol | Description | Symbol
Unary negation - Logical NOT ! Bitwise NOT ~ Assignment = delete delete
Increment ++ Less than < Bitwise Left Shift << Compound Assignment OP= typeof typeof
Decrement -- Greater than > Bitwise Right Shift >> void void
Multiplication * Less than or equal to <= Unsigned Right Shift >>>
Division / Greater than or equal to >= Bitwise AND &
Modulo arithmetic % Equality == Bitwise XOR ^
Addition + Inequality != Bitwise OR |
Subtraction - Logical AND &&
Logical OR ||
Conditional (trinary) ?:
Comma ,
Identity ===
Nonidentity !==

Operator Precedence
Operators in JScript are evaluated in a particular order. This order is known as the operator precedence. The following table lists the operators in highest to lowest precedence order. Operators in the same row are evaluated in left to right order.

Operator | Description
. [] () Field access, array indexing, and function calls
++ -- - ~ ! typeof new void delete | Unary operators, return data type, object creation, undefined values
* / % Multiplication, division, modulo division
+ - + Addition, subtraction, string concatenation
<< >> >>> Bit shifting
< <= > >= Less than, less than or equal to, greater than, greater than or equal to
== != === !== Equality, inequality, identity, nonidentity
& Bitwise AND
^ Bitwise XOR
| Bitwise OR
&& Logical AND
|| Logical OR
?: Conditional
= OP= | Assignment, assignment with operation
, Multiple evaluation

Parentheses are used to alter the order of evaluation. The expression within parentheses is fully evaluated before its value is used in the remainder of the statement.

An operator with higher precedence is evaluated before one with lower precedence. For example:

z = 78 * (96 + 3 + 45)

There are five operators in this expression: =, *, (), +, and +. According to precedence, they are evaluated in the following order: (), *, +, +, =.

  1. Evaluation of the expression within the parentheses is first: There are two addition operators, and they have the same precedence: 96 and 3 are added together and 45 is added to that total, resulting in a value of 144.
  2. Multiplication is next: 78 and 144 are multiplied, resulting in a value of 11232.
  3. Assignment is last: 11232 is assigned into z.


+ Operator

Microsoft® JScript™
+ Operator 		Language Reference
Version 1

See Also

Description
Used to sum two numbers or perform string concatenation.
Syntax
result = expression1 + expression2

The + operator syntax has these parts:

Part | Description
result | Any variable.
expression1 | Any expression.
expression2 | Any expression.

Remarks
The underlying subtype of the expressions determines the behavior of the + operator.

If | Then
Both expressions are numeric or Boolean | Add.
Both expressions are strings | Concatenate.
One expression is numeric and the other is a string | Concatenate.

For information on when a run-time error is generated by the + operator, see the Operator Behavior table.


+ Operator

Microsoft® JScript™
+ Operator
See Also 		Language Reference

+= Operator
Operator Behavior
Operator Precedence
Operator Summary


+= Operator

Microsoft® JScript™
+= Operator 		Language Reference
Version 1

See Also

Description
Used to increment a variable by a specified amount.
Syntax
result += expression

The += operator syntax has these parts:

Part | Description
result | Any variable.
expression | Any expression.

Remarks
Using this operator is exactly the same as specifying:
result = result + expression
The underlying subtype of the expressions determines the behavior of the += operator.

If | Then
Both expressions are numeric or Boolean | Add.
Both expressions are strings | Concatenate.
One expression is numeric and the other is a string | Concatenate.

For information on when a run-time error is generated by the += operator, see the Operator Behavior table.


+= Operator

Microsoft® JScript™
+= Operator
See Also 		Language Reference

+ Operator
Operator Behavior
Operator Precedence
Operator Summary


Compound Assignment Operators

Microsoft® JScript™
Compound Assignment Operators 		Language Reference

Addition (+=)
Bitwise AND (&=)
Bitwise OR (|=)
Bitwise XOr (^=)
Division (/=)
Left Shift (<<=)
Modulus (%=)
Multiplication (*=)
Right Shift (>>=)
Subtraction (-=)
Unsigned Right Shift (>>>=)


&& Operator

Microsoft® JScript™
&& Operator 		Language Reference
Version 1

See Also

Description
Used to perform a logical conjunction on two expressions.
Syntax
result = expression1 && expression2

The && operator syntax has these parts:

Part | Description
result | Any variable.
expression1 | Any expression.
expression2 | Any expression.

Remarks
If, and only if, both expressions evaluate to True, result is True. If either expression evaluates to False, result is False.

For information on when a run-time error is generated by the && operator, see the Operator Behavior table.

JScript uses the following rules for converting non-Boolean values to Boolean values:

  • All objects are considered true.
  • Strings are considered false if and only if they are empty.
  • null and undefined are considered false.
  • Numbers are false if and only if they are zero.


&& Operator

Microsoft® JScript™
&& Operator
See Also 		Language Reference

Operator Behavior
Operator Precedence
Operator Summary


= Operator

Microsoft® JScript™
= Operator 		Language Reference
Version 1

See Also

Description
Assigns a value to a variable.

Syntax
result = expression

The = operator syntax has these parts:

Part | Description
result | Any variable.
expression | Any numeric expression.

Remarks
As the = operator behaves like other operators, expressions using it have a value in addition to assigning that value into variable. This means that you can chain assignment operators as follows:
j = k = l = 0;
j, k, and l equal zero after the example statement is executed.


= Operator

Microsoft® JScript™
= Operator
See Also 		Language Reference

Compound Assignment Operators
Operator Behavior
Operator Precedence
Operator Summary


&= Operator

Microsoft® JScript™
&= Operator 		Language Reference
Version 1

See Also

Description
Used to perform a bitwise AND on an expression.
Syntax
result &= expression

The &= operator syntax has these parts:

Part | Description
result | Any variable.
expression | Any expression.

Remarks
Using this operator is exactly the same as specifying:
result = result & expression

The &= operator looks at the binary representation of the values of result and expression and does a bitwise AND operation on them. The output of this operation behaves like this:

0101    (result)
1100    (expression)
----
0100    (output)

Any time both of the expressions have a 1 in a digit, the result has a 1 in that digit. Otherwise, the result has a 0 in that digit.

For information on when a run-time error is generated by the &= operator, see the Operator Behavior table.


&= Operator

Microsoft® JScript™
&= Operator
See Also 		Language Reference

& Operator
Operator Behavior
Operator Precedence
Operator Summary


|= Operator

Microsoft® JScript™
|= Operator 		Language Reference
Version 1

See Also

Description
Used to perform a bitwise OR on an expression.
Syntax
result |= expression

The |= operator syntax has these parts:

Part | Description
result | Any variable.
expression | Any expression.

Remarks
Using this operator is exactly the same as specifying:
result = result | expression

The |= operator looks at the binary representation of the values of result and expression and does a bitwise OR operation on them. The result of this operation behaves like this:

0101    (result)
1100    (expression)
----
1101    (output)

Any time either of the expressions has a 1 in a digit, the result has a 1 in that digit. Otherwise, the result has a 0 in that digit.

For information on when a run-time error is generated by the |= operator, see the Operator Behavior table.


|= Operator

Microsoft® JScript™
|= Operator
See Also 		Language Reference

| Operator
Operator Behavior
Operator Precedence
Operator Summary


& Operator

Microsoft® JScript™
& Operator 		Language Reference
Version 1

See Also

Description
Used to perform a bitwise AND on two expressions.
Syntax
result = expression1 & expression2

The & operator syntax has these parts:

Part | Description
result | Any variable.
expression1 | Any expression.
expression2 | Any expression.

Remarks

The & operator looks at the binary representation of the values of two expressions and does a bitwise AND operation on them. The result of this operation behaves as follows:

0101    (expression1)
1100    (expression2)
----
0100    (result)

Any time both of the expressions have a 1 in a digit, the result has a 1 in that digit. Otherwise, the result has a 0 in that digit.

For information on when a run-time error is generated by the & operator, see the Operator Behavior table.


& Operator

Microsoft® JScript™
& Operator
See Also 		Language Reference

&= Operator
Operator Behavior
Operator Precedence
Operator Summary


~ Operator

Microsoft® JScript™
~ Operator 		Language Reference
Version 1

See Also

Description
Used to perform a bitwise NOT (negation) on an expression.
Syntax
result = ~ expression

The ~ operator syntax has these parts:

Part | Description
result | Any variable.
expression | Any expression.

Remarks
All unary operators, such as the ~ operator, evaluate expressions as follows:
  • If applied to undefined or null expressions, a run-time error is raised.
  • Objects are converted to strings.
  • Strings are converted to numbers if possible. If not, a run-time error is raised.
  • Boolean values are treated as numbers (0 if false, 1 if true).

The operator is applied to the resulting number.

The ~ operator looks at the binary representation of the values of the expression and does a bitwise negation operation on it. The result of this operation behaves as follows:

0101    (expression)
----
1010    (result)

Any digit that is a 1 in the expression becomes a 0 in the result. Any digit that is a 0 in the expression becomes a 1 in the result.


~ Operator

Microsoft® JScript™
~ Operator
See Also 		Language Reference

! Operator
Operator Behavior
Operator Precedence
Operator Summary


| Operator

Microsoft® JScript™
| Operator 		Language Reference
Version 1

See Also

Description
Used to perform a bitwise OR on two expressions.
Syntax
result = expression1 | expression2

The | operator syntax has these parts:

Part | Description
result | Any variable.
expression1 | Any expression.
expression2 | Any expression.

Remarks
The | operator looks at the binary representation of the values of two expressions and does a bitwise OR operation on them. The result of this operation behaves as follows:
0101    (expression1)
1100    (expression2)
----
1101    (result)

Any time either of the expressions has a 1 in a digit, the result will have a 1 in that digit. Otherwise, the result will have a 0 in that digit.

For information on when a run-time error is generated by the | operator, see the Operator Behavior table.


| Operator

Microsoft® JScript™
| Operator
See Also 		Language Reference

|= Operator
Operator Behavior
Operator Precedence
Operator Summary


, Operator

Microsoft® JScript™
, Operator 		Language Reference
Version 1

See Also

Description
Causes two expressions to be executed sequentially.
Syntax
expression1, expression2

The , operator syntax has these parts:

Part | Description
expression1 | Any expression.
expression2 | Any expression.

Remarks
The , operator causes the expressions on either side of it to be executed in left-to-right order, and obtain the value of the expression on the right. The most common use for the , operator is in the increment expression of a for loop. For example:
for (i = 0; i < 10; i++, j++)
{
  k = i + j;
}
The for statement only allows a single expression to be executed at the end of every pass through a loop. The , operator is used to allow multiple expressions to be treated as a single expression, thereby getting around the restriction.


, Operator

Microsoft® JScript™
, Operator
See Also 		Language Reference

for Statement
Operator Behavior
Operator Precedence
Operator Summary


?: Operator

Microsoft® JScript™
?: Operator 		Language Reference
Version 1

See Also

Description
Executes one of two statements depending on a condition.
Syntax
test ? statement1 : statement2

The ?: operator syntax has these parts:

Part | Description
test | Any Boolean expression.
statement1 | A statement executed if test is true. May be a compound statement.
statement2 | A statement executed if test is false. May be a compound statement.

Remarks
The ?: operator is a shortcut for an if...else statement. It is typically used as part of a larger expression where an if...else statement would be awkward. For example:
var now = new Date();
var greeting = "Good" + ((now.getHours() > 17) ? " evening." : " day.");
The example creates a string containing "Good evening." if it is after 6pm. The equivalent code using an if...else statement would look as follows:
var now = new Date();
var greeting = "Good";
if (now.getHours() > 17)
   greeting += " evening.";
else
   greeting += " day.";


?: Operator

Microsoft® JScript™
?: Operator
See Also 		Language Reference

if...else Statement
Operator Behavior
Operator Precedence
Operator Summary


delete Operator

Microsoft® JScript™
delete Operator 		Language Reference
Version 3

See Also

Description
Deletes a property from an object, or removes an element from an array.
Syntax
delete expression

Where expression is a valid JScript expression that usually (but does not have to) result in a property name or array element.

Remarks
If the result of expression is an object, and the property specified in expression exists, and the object will not allow it to be deleted, false is returned.

In all other cases true is returned.


delete Operator

Microsoft® JScript™
delete Operator
See Also 		Language Reference

Operator Behavior
Operator Precedence
Operator Summary


/= Operator

Microsoft® JScript™
/= Operator 		Language Reference
Version 1

See Also

Description
Used to divide a variable by an expression.

Syntax
result /= expression

The /= operator syntax has these parts:

Part | Description
result | Any numeric variable.
expression | Any numeric expression.

Remarks
Using the /= operator is exactly the same as specifying:
result = result / expression

For information on when a run-time error is generated by the /= operator, see the Operator Behavior table.


/= Operator

Microsoft® JScript™
/= Operator
See Also 		Language Reference

/ Operator
Operator Behavior
Operator Precedence
Operator Summary


/ Operator

Microsoft® JScript™
/ Operator 		Language Reference
Version 1

See Also

Description
Used to divide two numbers and return a numeric result.
Syntax
result = number1 / number2

The / operator syntax has these parts:

Part | Description
result | Any numeric variable.
number1 | Any numeric expression.
number2 | Any numeric expression.

Remarks
For information on when a run-time error is generated by the / operator, see the Operator Behavior table.


/ Operator

Microsoft® JScript™
/ Operator
See Also 		Language Reference

/= Operator
Operator Behavior
Operator Precedence
Operator Summary


++ and -- Operators

Microsoft® JScript™
++ and -- Operators 		Language Reference
Version 1

See Also

Description
Used to increment or decrement a variable by one.
Syntax
result = ++variable
result = --variable
result = variable++
result = variable--
Syntax 2
++variable
--variable
variable++
variable--

The syntax of the ++ and -- operators has these parts:

Part | Description
result | Any variable.
variable | Any variable.

Remarks
The increment and decrement operators are used as a shortcut to modify the value stored in a variable. The value of an expression containing one of these operators depends on whether the operator comes before or after the variable:
var j, k;
k = 2;
j = ++k;
j is assigned the value 3, as the increment occurs before the expression is evaluated. Contrast the following example:
var j, k;
k = 2;
j = k++;
Here, j is assigned the value 2, as the increment occurs after the expression is evaluated.


++ and -- Operators

Microsoft® JScript™
++ and -- Operators
See Also 		Language Reference

Operator Behavior
Operator Precedence
Operator Summary


Operator Summary

Microsoft® JScript™
Operator Summary 		Language Reference
Version 1

Computational
Addition (+)
Decrement (--)
Division (/)
Increment (++)
Modulus (%)
Multiplication (*)
Subtraction (-)
Unary negation (-)
Logical
Comma (,)
Conditional (trinary) (?:)
Equality (==)
Greater than (>)
Greater than or equal to (>=)
Identity (===)
Inequality (!=)
Less than (<)
Less than or equal to (<=)
Logical AND (&&)
Logical NOT (!)
Logical OR (||)
Nonidentity (!==)
Bitwise
Bitwise AND (&)
Bitwise Left Shift (<<)
Bitwise NOT (~)
Bitwise OR (|)
Bitwise Right Shift (>>)
Bitwise XOR (^)
Unsigned Right Shift (>>>)
Assignment
Assignment (=)
Compound Assignment Operators
Miscellaneous
delete
new
typeof
void


<<= Operator

Microsoft® JScript™
<<= Operator 		Language Reference
Version 1

See Also

Description
Used to shift the bits of an expression to the left.
Syntax
result <<= expression

The <<= operator syntax has these parts:

Part | Description
result | Any variable.
expression | Any expression.

Remarks
Using the <<= operator is exactly the same as specifying:
result = result << expression

The <<= operator shifts the bits of result left by the number of bits specified in expression. For example:

var temp
temp = 14
temp <<= 2

The variable temp has a value of 56 as 14 (00001110 in binary) shifted left two bits equals 56 (00111000 in binary). Bits are filled in with zeroes when shifting.

For information on when a run-time error is generated by the <<= operator, see the Operator Behavior table.


<<= Operator

Microsoft® JScript™
<<= Operator
See Also 		Language Reference

<< Operator
>> Operator
>>> Operator
Operator Behavior
Operator Precedence
Operator Summary


<< Operator

Microsoft® JScript™
<< Operator 		Language Reference
Version 1

See Also

Description
Used to shift the bits of an expression to the left.
Syntax
result = expression1 << expression2

The << operator syntax has these parts:

Part | Description
result | Any variable.
expression1 | Any expression.
expression2 | Any expression.

Remarks

The << operator shifts the bits of expression1 left by the number of bits specified in expression2. For example:

var temp
temp = 14 << 2

The variable temp has a value of 56 as 14 (00001110 in binary) shifted left two bits equals 56 (00111000 in binary).

For information on when a run-time error is generated by the << operator, see the Operator Behavior table.


<< Operator

Microsoft® JScript™
<< Operator
See Also 		Language Reference

<<= Operator
>> Operator
>>> Operator
Operator Behavior
Operator Precedence
Operator Summary


% Operator

Microsoft® JScript™
% Operator 		Language Reference
Version 1

See Also

Description
Used to divide two numbers and return only the remainder.
Syntax
result = number1 % number2

The % operator syntax has these parts:

Part | Description
result | Any variable.
number1 | Any numeric expression.
number2 | Any numeric expression.

Remarks
The modulus, or remainder, operator divides number1 by number2 (rounding floating-point numbers to integers) and returns only the remainder as result. For example, in the following expression, A (which is result) equals 5.

A = 19 % 6.7

For information on when a run-time error is generated by the % operator, see the Operator Behavior table.


% Operator

Microsoft® JScript™
% Operator
See Also 		Language Reference

%= Operator
Operator Behavior
Operator Precedence
Operator Summary


%= Operator

Microsoft® JScript™
%= Operator 		Language Reference
Version 1

See Also

Description
Used to divide two numbers and return only the remainder.
Syntax
result %= expression

The %= operator syntax has these parts:

Part | Description
result | Any variable.
expression | Any numeric expression.

Remarks
Using the %= operator is exactly the same as specifying:
result = result % expression

For information on when a run-time error is generated by the %= operator, see the Operator Behavior table.


%= Operator

Microsoft® JScript™
%= Operator
See Also 		Language Reference

% Operator
Operator Behavior
Operator Precedence
Operator Summary


*= Operator

Microsoft® JScript™
*= Operator 		Language Reference
Version 1

See Also

Description
Used to multiply a number by another number.
Syntax
result *= expression

The *= operator syntax has these parts:

Part | Description
result | Any variable.
expression | Any expression.

Remarks
Using the *= operator is exactly the same as specifying:
result = result * expression

For information on when a run-time error is generated by the *= operator, see the Operator Behavior table.


*= Operator

Microsoft® JScript™
*= Operator
See Also 		Language Reference

* Operator
Operator Behavior
Operator Precedence
Operator Summary


* Operator

Microsoft® JScript™
* Operator 		Language Reference
Version 1

See Also

Description
Used to multiply two numbers.

Syntax
result = number1*number2

The * operator syntax has these parts:

Part | Description
result | Any variable.
number1 | Any expression.
number2 | Any expression.

Remarks
For information on when a run-time error is generated by the * operator, see the Operator Behavior table.


* Operator

Microsoft® JScript™
* Operator
See Also 		Language Reference

*= Operator
Operator Behavior
Operator Precedence
Operator Summary


new Operator

Microsoft® JScript™
new Operator
Language Reference
Version 1

See Also

Description

Creates a new object.

Syntax

new constructor[(arguments)]

The constructor argument calls object's constructor. The parentheses can be omitted if the constructor takes no arguments.

Remarks
The new operator performs the following tasks:
  1. It creates an object with no members.
  2. It calls the constructor for that object, passing a pointer to the newly created object as the this pointer.
The constructor then initializes the object according to the arguments passed to the constructor. These are examples of valid uses of the new operator:
my_object = new Object;
my_array = new Array();
my_date = new Date("Jan 5 1996");


new Operator

Microsoft® JScript™
new Operator
See Also 		Language Reference

function Statement


! Operator

Microsoft® JScript™
! Operator 		Language Reference
Version 1

See Also

Description
Used to perform logical negation on an expression.
Syntax
result = !expression

The ! operator syntax has these parts:

Part | Description
result | Any variable.
expression | Any expression.

Remarks
The following table illustrates how result is determined.

If expression is | Then result is
True | False
False | True

All unary operators, such as the ! operator, evaluate expressions as follows:

  • If applied to undefined or null expressions, a run-time error is raised.
  • Objects are converted to strings.
  • Strings are converted to numbers if possible. If not, a run-time error is raised.
  • Boolean values are treated as numbers (0 if false, 1 if true).
The operator is applied to the resulting number.

For the ! operator, if expression is nonzero, result is zero. If expression is zero, result is 1.


! Operator

Microsoft® JScript™
! Operator
See Also 		Language Reference

~ Operator
Operator Behavior
Operator Precedence
Operator Summary


|| Operator

Microsoft® JScript™
|| Operator 		Language Reference
Version 1

See Also

Description
Used to perform a logical disjunction on two expressions.
Syntax
result = expression1 || expression2

The || operator syntax has these parts:

Part | Description
result | Any variable.
expression1 | Any expression.
expression2 | Any expression.

Remarks
If either or both expressions evaluate to True, result is True. The following table illustrates how result is determined:

If expression1 is | And expression2 is | The result is
True | True | True
True | False | True
False | True | True
False | False | False

For information on when a run-time error is generated by the && operator, see the Operator Behavior table.

JScript uses the following rules for converting non-Boolean values to Boolean values:

  • All objects are considered true.
  • Strings are considered false if and only if they are empty.
  • null and undefined are considered false.
  • Numbers are false if and only if they are 0.


|| Operator

Microsoft® JScript™
|| Operator
See Also 		Language Reference

Operator Behavior
Operator Precedence
Operator Summary


>>= Operator

Microsoft® JScript™
>>= Operator 		Language Reference
Version 1

See Also

Description
Used to shift the bits of an expression to the right, preserving sign.
Syntax
result >>= expression

The >>= operator syntax has these parts:

Part | Description
result | Any variable.
expression | Any expression.

Remarks
Using the >>= operator is exactly the same as specifying:
result = result >> expression

The >>= operator shifts the bits of result right by the number of bits specified in expression. The sign bit of result is used to fill the digits from the left. Digits shifted off the right are discarded. For example, after the following code is evaluated, temp has a value of -4: 14 (11110010 in binary) shifted right two bits equals -4 (11111100 in binary).

var temp
temp = -14
temp >>= 2

For information on when a run-time error is generated by the >>= operator, see the Operator Behavior table.


>>= Operator

Microsoft® JScript™
>>= Operator
See Also 		Language Reference

<< Operator
>> Operator
>>> Operator
Operator Behavior
Operator Precedence
Operator Summary


>> Operator

Microsoft® JScript™
>> Operator 		Language Reference
Version 1

See Also

Description
Used to shift the bits of an expression to the right, maintaining sign.
Syntax
result = expression1 >> expression2

The >> operator syntax has these parts:

Part | Description
result | Any variable.
expression1 | Any expression.
expression2 | Any expression.

Remarks

The >> operator shifts the bits of expression1 right by the number of bits specified in expression2. The sign bit of expression1 is used to fill the digits from the left. Digits shifted off the right are discarded. For example, after the following code is evaluated, temp has a value of -4: 14 (11110010 in binary) shifted right two bits equals -4 (11111100 in binary).

var temp
temp = -14 >> 2

For information on when a run-time error is generated by the >> operator, see the Operator Behavior table.


>> Operator

Microsoft® JScript™
>> Operator
See Also 		Language Reference

<< Operator
>>= Operator
>>> Operator
Operator Behavior
Operator Precedence
Operator Summary


-= Operator

Microsoft® JScript™
-= Operator 		Language Reference
Version 1

See Also

Description
Used to subtract the value of an expression from a variable.
Syntax

result -= expression

The -= operator syntax has these parts:

Part | Description
result | Any numeric variable.
expression | Any numeric expression.

Remarks
Using the -= operator is exactly the same as doing the following:
result = result - expression

For information on when a run-time error is generated by the - operator, see the Operator Behavior table.


-= Operator

Microsoft® JScript™
-= Operator
See Also 		Language Reference

- Operator
Operator Behavior
Operator Precedence
Operator Summary


- Operator

Microsoft® JScript™
- Operator 		Language Reference
Version 1

See Also

Description
Used to find the difference between two numbers or to indicate the negative value of a numeric expression.

Syntax 1
result = number1 - number2
Syntax 2
-number

The - operator syntax has these parts:

Part | Description
result | Any numeric variable.
number | Any numeric expression.
number1 | Any numeric expression.
number2 | Any numeric expression.

Remarks
In Syntax 1, the - operator is the arithmetic subtraction operator used to find the difference between two numbers. In Syntax 2, the - operator is used as the unary negation operator to indicate the negative value of an expression.

For information on when a run-time error is generated by Syntax 1, see the Operator Behavior table.

For Syntax 2, as for all unary operators, expressions are evaluated as follows:

  • If applied to undefined or null expressions, a run-time error is raised.
  • Objects are converted to strings.
  • Strings are converted to numbers if possible. If not, a run-time error is raised.
  • Boolean values are treated as numbers (0 if false, 1 if true).
The operator is applied to the resulting number. In Syntax 2, if the resulting number is nonzero, result is equal to the resulting number with its sign reversed. If the resulting number is zero, result is zero.


- Operator

Microsoft® JScript™
- Operator
See Also 		Language Reference

-= Operator
Operator Behavior
Operator Precedence
Operator Summary


typeof Operator

Microsoft® JScript™
typeof Operator 		Language Reference
Version 1

See Also

Description
Used to determine the type of an expression.
Syntax
typeof [ ( ] expression [ ) ] ;

The expression argument is any expression for which type information is sought.

Remarks
The typeof operator returns type information as a string. There are six possible values that typeof returns: "number," "string," "boolean," "object," "function," and "undefined."

The parentheses are optional in the typeof syntax.


typeof Operator

Microsoft® JScript™
typeof Operator
See Also 		Language Reference

Operator Behavior
Operator Precedence
Operator Summary


>>>= Operator

Microsoft® JScript™
>>>= Operator 		Language Reference
Version 1

See Also

Description
Used to make an unsigned right shift of the bits in a variable.

Syntax
result >>>= expression

The >>>= operator syntax has these parts:

Part | Description
result | Any variable.
expression | Any expression.

Remarks
Using the >>>= operator is exactly the same as doing the following:
result = result >>> expression

The >>>= operator shifts the bits of result right by the number of bits specified in expression. Zeroes are filled in from the left. Digits shifted off the right are discarded. For example:

var temp
temp = -14
temp >>>= 2

The variable temp has a value of 1073741820 as -14 (11111111 11111111 11111111 11110010 in binary) shifted right two bits equals 1073741820 (00111111 11111111 11111111 11111100 in binary).

For information on when a run-time error is generated by the >>>= operator, see the Operator Behavior table.


>>>= Operator

Microsoft® JScript™
>>>= Operator
See Also 		Language Reference

>>> Operator
<< Operator
>> Operator
Operator Behavior
Operator Precedence
Operator Summary


>>> Operator

Microsoft® JScript™
>>> Operator 		Language Reference
Version 1

See Also

Description
Used to make an unsigned right shift of the bits in an expression.
Syntax
result = expression1 >>> expression2

The >>> operator syntax has these parts:

Part | Description
result | Any variable.
expression1 | Any expression.
expression2 | Any expression.

Remarks

The >>> operator shifts the bits of expression1 right by the number of bits specified in expression2. Zeroes are filled in from the left. Digits shifted off the right are discarded. For example:

var temp
temp = -14 >>> 2

The variable temp has a value of 1073741820 as -14 (11111111 11111111 11111111 11110010 in binary) shifted right two bits equals 1073741820 (00111111 11111111 11111111 11111100 in binary).

For information on when a run-time error is generated by the >>> operator, see the Operator Behavior table.


>> Operator

Microsoft® JScript™
>>> Operator
See Also 		Language Reference

>>>= Operator
<< Operator
>> Operator
Operator Behavior
Operator Precedence
Operator Summary


void Operator

Microsoft® JScript™
void Operator 		Language Reference
Version 2

See Also

Description
Discards its operator and returns undefined.
Syntax
void expression

The expression argument is any valid JScript expression.

Remarks
The void operator evaluates its expression, and returns undefined. It is most useful in situations where you want an expression evaluated but do not want the results visible to the remainder of the script.


void Operator

Microsoft® JScript™
void Operator
See Also 		Language Reference

Operator Behavior
Operator Precedence
Operator Summary


^ Operator

Microsoft® JScript™
^ Operator 		Language Reference
Version 1

See Also

Description
Used to perform a bitwise exclusive OR on two expressions.
Syntax
result = expression1 ^ expression2

The ^ operator syntax has these parts:

Part | Description
result | Any variable.
expression1 | Any expression.
expression2 | Any expression.

Remarks

The ^ operator looks at the binary representation of the values of two expressions and does a bitwise exclusive OR operation on them. The result of this operation behaves as follows:

0101    (expression1)
1100    (expression2)
----
1001    (result)

When one, and only one, of the expressions has a 1 in a digit, the result has a 1 in that digit. Otherwise, the result has a 0 in that digit.

For information on when a run-time error is generated by the ^ operator, see the Operator Behavior table.


^ Operator

Microsoft® JScript™
^ Operator
See Also 		Language Reference

^= Operator
Operator Behavior
Operator Precedence
Operator Summary


^= Operator

Microsoft® JScript™
^= Operator 		Language Reference
Version 1

See Also

Description
Used to perform a bitwise exclusive OR on an expression.
Syntax
result ^= expression

The ^= operator syntax has these parts:

Part | Description
result | Any variable.
expression | Any expression.

Remarks

Using the ^= operator is exactly the same as specifying:

result = result ^ expression

The ^= operator looks at the binary representation of the values of two expressions and does a bitwise exclusive OR operation on them. The result of this operation behaves as follows:

0101    (result)
1100    (expression)
----
1001    (result)

When one, and only one, of the expressions has a 1 in a digit, the result has a 1 in that digit. Otherwise, the result has a 0 in that digit.

For information on when a run-time error is generated by the ^= operator, see the Operator Behavior table.


^= Operator

Microsoft® JScript™
^= Operator
See Also 		Language Reference

^ Operator
Operator Behavior
Operator Precedence
Operator Summary


index Property

Microsoft® JScript™
index Property 		Language Reference
Version 3

See Also Applies To

Description
Indicates where the first successful match begins in a string that was searched.
Syntax
RegExp.index
Remarks
The index property is zero-based. Its value is modified whenever a successful match is made.


index Property

Microsoft® JScript™
index Property
Applies To 		Language Reference

RegExp Object


index Property

Microsoft® JScript™
index Property
See Also 		Language Reference

RegExp Object Properties
Regular Expression Syntax


input Property

Microsoft® JScript™
input ($_) Property 		Language Reference
Version 3

See Also Applies To

Description
Contains the string against which a search was performed. Read-only
Syntax
RegExp.input
Short Syntax
RegExp.$_
Remarks
The value of input property is modified whenever a successful match is made.


input Property

Microsoft® JScript™
input Property
Applies To 		Language Reference

RegExp Object


input Property

Microsoft® JScript™
input Property
See Also 		Language Reference

RegExp Object Properties
Regular Expression Syntax


lastIndex Property (RegExp)

Microsoft® JScript™
lastIndex Property (RegExp) 		Language Reference
Version 3

See Also Applies To

Description
Indicates where the last successful match begins in a string that was searched.
Syntax
RegExp.lastIndex
Remarks
The lastIndex property is zero-based. Its value is modified whenever a successful match is made.


lastIndex Property (RegExp)

Microsoft® JScript™
lastIndex Property (RegExp)
Applies To 		Language Reference

RegExp Object


lastIndex Property (RegExp)

Microsoft® JScript™
lastIndex Property (RegExp)
See Also 		Language Reference

RegExp Object Properties
Regular Expression Syntax


lastMatch Property

Microsoft® JScript™
lastMatch ($&) Property 		Language Reference
Version 3

See Also Applies To

Description
Specifies the last matched characters. Read-onlu
Syntax
RegExp.lastMatch
Short Syntax
RegExp.$&
Remarks
The value of the lastMatch property is modified whenever a successful match is made.


lastMatch Property

Microsoft® JScript™
lastMatch Property
Applies To 		Language Reference

RegExp Object


lastMatch Property

Microsoft® JScript™
lastMatch Property
See Also 		Language Reference

RegExp Object Properties
Regular Expression Syntax


lastParen Property

Microsoft® JScript™
lastParen ($+) Property 		Language Reference
Version 3

See Also Applies To

Description
Specifies the last parenthesized substring match, if any. Read-only.
Syntax
RegExp.lastParen
Short Syntax
RegExp.$+
Remarks
The value of the lastParen property is modified whenever a successful parenthesized match is made.


lastParen Property

Microsoft® JScript™
lastParen Property
Applies To 		Language Reference

RegExp Object


lastParen Property

Microsoft® JScript™
lastParen Property
See Also 		Language Reference

RegExp Object Properties
Regular Expression Syntax


leftContext Property

Microsoft® JScript™
leftContext ($`) Property 		Language Reference
Version 3

See Also Applies To

Description
Specifies the input string up to the most recent match. Read-only
Syntax
RegExp.leftContext
Short Syntax
RegExp.$`
Remarks
The value of the leftContext property is modified whenever a successful match is made.


leftContext Property

Microsoft® JScript™
leftContext Property
Applies To 		Language Reference

RegExp Object


leftContext Property

Microsoft® JScript™
leftContext Property
See Also 		Language Reference

RegExp Object Properties
Regular Expression Syntax


$1...$9 Property

Microsoft® JScript™
$1...$9 Property 		Language Reference
Version 3

See Also Applies To

Description
Specifies the nine most-recently memorized portions found during pattern matching. Read-only
Syntax
RegExp.$n

The n argument is a number between 1 and 9.

Remarks
The value of the $1...$9 property is modified whenever a successful parenthesized match is made. Any number of parenthesized substrings may be specified in a regular expression pattern, but only the nine most recent can be stored.


$1..$9 Properties

Microsoft® JScript™
$1..$9 Properties
Applies To 		Language Reference

RegExp Object


$1...$9 Properties

Microsoft® JScript™
$1...$9 Properties
See Also 		Language Reference

RegExp Object Properties
Regular Expression Syntax


multiline Property

Microsoft® JScript™
multiline ($*) Property 		Language Reference
Version 3

See Also Applies To

Description
Indicates whether searching continued across line breaks. Read-only.
Syntax
RegExp.multiline
Short Syntax
RegExp.$*
Remarks
The value of the multiline property is modified whenever a successful match is made. If multiline is true, searching was performed across line breaks; otherwise, multiline returns false.


multiline Property

Microsoft® JScript™
multiline Property
Applies To 		Language Reference

RegExp Object


multiline Property

Microsoft® JScript™
multiline Property
See Also 		Language Reference

RegExp Object Properties
Regular Expression Syntax


compile Method

Microsoft® JScript™
compile Method 		Language Reference
Version 3

See Also Applies To

Description
Compiles a regular expression into an internal format.
Syntax
rgexp.compile(pattern)

The compile method syntax has these parts:

Part | Description
rgexp | Required. A Regular Expression object. Can be a variable name or a literal.
pattern | Required. A string expression containing a regular expression pattern to be compiled.

Remarks
The compile method converts pattern into an internal format for faster execution. This allows for more efficient use of regular expressions in loops, for example.


compile Method

Microsoft® JScript™
compile Method
Applies To 		Language Reference

Regular Expression Object


compile Method

Microsoft® JScript™
compile Method
See Also 		Language Reference

Regular Expression Object Methods
Regular Expression Object Properties
Regular Expression Syntax


exec Method

Microsoft® JScript™
exec Method 		Language Reference
Version 3

See Also Applies To

Description
Executes a search for a match in a specified string.
Syntax
rgexp.exec(str)

The exec method syntax has these parts:

Part | Description
rgexp | Required. A Regular Expression object. Can be a variable name or a literal.
str | Required. The string to perform a search on.

Remarks
The results of an exec method search are placed into an array.

If the exec method does not find a match, it returns null. If it finds one or more matches, the exec method returns an array, and the RegExp object is updated to reflect the results of the search.


exec Method

Microsoft® JScript™
exec Method
Applies To 		Language Reference

Regular Expression Object


exec Method

Microsoft® JScript™
exec Method
See Also 		Language Reference

RegExp Object
Regular Expression Object Methods
Regular Expression Object Properties
Regular Expression Syntax


global Property

Microsoft® JScript™
global Property 		Language Reference
Version 3

See Also Applies To

Description
Indicates whether the global switch (g) has been used. Read-only.
Syntax
rgexp.global

The rgexp argument is a Regular Expression object.

Remarks
The global property contains true if the global (g) switch is used with a regular expression, and false if not.


global Property

Microsoft® JScript™
global Property
Applies To 		Language Reference

Regular Expression Object


global Property

Microsoft® JScript™
global Property
See Also 		Language Reference

Regular Expression Object Methods
Regular Expression Object Properties
Regular Expression Syntax


ignoreCase Property

Microsoft® JScript™
ignoreCase Property 		Language Reference
Version 3

See Also Applies To

Description
Indicates whether the ignore case (i) switch has been used. Read-only.
Syntax
rgexp.ignoreCase

The rgexp argument is a Regular Expression object.

Remarks
The ignoreCase property contains true if the ignore case (i) switch is used with a regular expression, and false if not.


ignoreCase Property

Microsoft® JScript™
ignoreCase Property
Applies To 		Language Reference

Regular Expression Object


ignoreCase Property

Microsoft® JScript™
ignoreCase Property
See Also 		Language Reference

Regular Expression Object Methods
Regular Expression Object Properties
Regular Expression Syntax


lastIndex Property (Regular Expression)

Microsoft® JScript™
lastIndex Property (Regular Expression) 		Language Reference
Version 3

See Also Applies To

Description
Specifies the index at which to start the next match.
Syntax
rgexp.lastIndex [= index]

The lastIndex method syntax has these parts:

Part | Description
rgexp | Required. A Regular Expression object. Can be a variable name or a literal.
index | The index from which to begin the next search.

Remarks
The lastIndex property is modified by the exec method, and the match, replace, and split methods of the String object.

The following rules apply to values of lastIndex:

  • If lastIndex is greater than the length of the string, the test and exec methods fail, and lastIndex is set to zero.
  • If lastIndex is equal to the length of the string, the regular expression matches if the pattern matches the empty string. Otherwise, the match fails and lastIndex is reset to zero.
  • Otherwise, lastIndex is set to the next position following the most recent match.


lastIndex Property (Regular Expression)

Microsoft® JScript™
lastIndex Property (Regular Expression)
Applies To 		Language Reference

Regular Expression Object


lastIndex Property (Regular Expression)

Microsoft® JScript™
lastIndex Property (Regular Expression)
See Also 		Language Reference

match Method
Regular Expression Object Methods
Regular Expression Object Properties
Regular Expression Syntax
replace Method
split Method
String Object


source Property

Microsoft® JScript™
source Property 		Language Reference
Version 3

See Also Applies To

Description
Contains the text of the regular expression pattern. Read-only.
Syntax
rgexp.source

The rgexp argument is a Regular expression object. It can be a variable name or a literal.


source Property

Microsoft® JScript™
source Property
Applies To 		Language Reference

Regular Expression Object


source Property

Microsoft® JScript™
source Property
See Also 		Language Reference

Regular Expression Object Methods
Regular Expression Object Properties
Regular Expression Syntax


test Method

Microsoft® JScript™
test Method 		Language Reference
Version 3

See Also Applies To

Description
Tests whether a pattern exists in a string.
Syntax
rgexp.test(str)

The test method syntax has these parts:

Part | Description
rgexp | Required. A Regular Expression object. Can be a variable name or a literal.
str | Required. The string to test a search on.

Remarks
The test method checks to see if a pattern exists within a string and returns true if so, and false otherwise.

The RegExp object is not modified by the test method.


test Method

Microsoft® JScript™
test Method
Applies To 		Language Reference

Regular Expression Object


test Method

Microsoft® JScript™
test Method
See Also 		Language Reference

RegExp Object
Regular Expression Object Methods
Regular Expression Object Properties
Regular Expression Syntax


rightContext Property

Microsoft® JScript™
rightContext ($') Property 		Language Reference
Version 3

See Also Applies To

Description
Specifies the input string past the most recent match. Read-only.
Syntax
RegExp.rightContext
Short Syntax
RegExp.$'
Remarks
The value of the rightContext property is modified whenever a successful match is made.


rightContext Property

Microsoft® JScript™
rightContext Property
Applies To 		Language Reference

RegExp Object


rightContext Property

Microsoft® JScript™
rightContext Property
See Also 		Language Reference

$1...$9 Properties
index Property
input Property
lastIndex Property
lastMatch Property
lastParen Property
leftContext Property
multiline Property


Regular Expression Syntax

Microsoft® JScript™
Regular Expression Syntax 		Language Reference
Version 3

See Also Applies To

Description
Special characters and sequences are used in writing patterns for regular expressions. The table that follows details them and includes short examples showing how the characters are used.

Character | Description
\ Marks the next character as special. /n/ matches the character "n". The sequence /\n/ matches a linefeed or newline character.
^ Matches the beginning of input or line.
$ Matches the end of input or line.
* Matches the preceding character zero or more times. /zo*/ matches either "z" or "zoo."
+ Matches the preceding character one or more times. /zo+/ matches "zoo" but not "z."
? Matches the preceding character zero or one time. /a?ve?/ matches the "ve" in "never."
. Matches any single character except a newline character.
(pattern) | Matches pattern and remembers the match. The matched substring can be retrieved from the result Array object elements [1]...[n] or the RegExp object's $1...$9 properties. To match parentheses characters, (), use "\(" or "\)".
x|y | Matches either x or y. /z|food?/ matches "zoo" or "food."
{n} | n is a nonnegative integer. Matches exactly n times. /o{2}/ does not match the "o" in "Bob," but matches the first two o's in "foooood."
{n,} | n is a nonnegative integer. Matches at least n times. /o{2,}/ does not match the "o" in "Bob" and matches all the o's in "foooood." /o{1,}/ is equivalent to /o+/.
{n,m} | m and n are nonnegative integers. Matches at least n and at most m times. /o{1,3}/ matches the first three o's in "fooooood."
[xyz] | A character set. Matches any one of the enclosed characters. /[abc]/ matches the "a" in "plain."
[^xyz] | A negative character set. Matches any character not enclosed. /[^abc]/ matches the "p" in "plain."
\b | Matches a word boundary, such as a space. /ea*r\b/ matches the "er" in "never early."
\B | Matches a nonword boundary. /ea*r\B/ matches the "ear" in "never early."
\d | Matches a digit character. Equivalent to [0-9].
\D | Matches a nondigit character. Equivalent to [^0-9].
\f | Matches a form-feed character.
\n | Matches a linefeed character.
\r | Matches a carriage return character.
\s | Matches any white space including space, tab, form-feed, and so forth. Equivalent to [ \f\n\r\t\v]
\S | Matches any nonwhite space character. Equivalent to [^ \f\n\r\t\v]
\t | Matches a tab character.
\v | Matches a vertical tab character.
\w | Matches any word character including underscore. Equivalent to [A-Za-z0-9_].
\W | Matches any nonword character. Equivalent to [^A-Za-z0-9_].
\num | Matches num, where num is a positive integer. A reference back to remembered matches. \1 matches what is stored in RegExp.$1.
/n/ | Matches n, where n is an octal, hexadecimal, or decimal escape value. Allows embedding of ASCII codes into regular expressions.


test Method

Microsoft® JScript™
test Method
Applies To 		Language Reference

RegExp Object
Regular Expression Object


test Method

Microsoft® JScript™
test Method
See Also 		Language Reference

String Object


JScript Reserved Keywords

Microsoft® JScript™
JScript Reserved Keywords
 JScript Tutorial
Previous
Next

JScript has a number of reserved keywords. These words come in three types: JScript reserved keywords, future reserved words, and words to avoid.

JScript Keywords
break | false | in | this | void
continue | for | new | true | while
delete | function | null | typeof | with
else | if | return | var

JScript Future Keywords
case | debugger | export | super
catch | default | extends | switch
class | do | finally | throw
const | enum | import | try

The words to avoid are any that are already the names of intrinsic JScript objects or functions. Words like String or parseInt are included in this.

Using any of the keywords from the first two categories causes a compilation error when your script is first loaded. Using a reserved word from the third set can cause odd behavior problems if you attempt to use both your variable and the original entity of the same name in the same script. For example, the following script does not do quite what you think it should:

var String;
var text = new String("This is a string object");

In this case, you get an error saying that String is not an object. Many cases of using a pre-existing identifier aren't this obvious.


break Statement

Microsoft® JScript™
break Statement
Language Reference
Version 1

See Also

Description
Terminates the current loop, or if in conjunction with a label, terminates the associated statement.
Syntax
break [label];

The optional label argument specifies the label of the statement you are breaking from.

Remarks
You typically use the break statement in switch statements and while, for, for...in, or do...while loops. You most commonly use the label argument in switch statements, but it can be used in any statement, whether simple or compound.

Executing the break statement exits from the current loop or statement, and begins script execution with the statement immediately following.


break Statement

Microsoft® JScript™
break Statement
See Also 		Language Reference

continue Statement
do...while Statement
for Statement
for...in Statement
Labeled Statements
while Statement


@cc_on Statement

Microsoft® JScript™
@cc_on Statement 		Language Reference
Version 3

See Also

Description
Activates conditional compilation support.
Syntax
@cc_on
Remarks
The @cc_on statement activates conditional compilation in the scripting engine.

It is strongly recommended that you use the @cc_on statement in a comment, so that browsers that do not support conditional compilation will accept your script as valid syntax:

/*@cc_on*/
...
(remainder of script)
Alternatively, an @if or @set statement outside of a comment also activates conditional compilation.


@cc_on Statement

Microsoft® JScript™
@cc_on Statement
See Also 		Language Reference

Conditional Compilation
Conditional Compilation Variables
@if Statement
@set Statement


Comment Statements

Microsoft® JScript™
Comment Statements
Language Reference
Version 1

Description

Causes comments to be ignored by the JScript parser.

Syntax 1
Single-line Comment:
// comment
Syntax 2
Multiline Comment:
/*
comment
*/

The comment argument is the text of any comment you want to include in your script.

Syntax 3
//@CondStatement
Syntax 4
/*@
CondStatement
@*/

The CondStatement argument is conditional compilation code to be used if conditional compilation is activated. If Syntax 3 is used, there can be no space between the "//" and "@" characters.

Remarks
Use comments to keep parts of a script from being read by the JScript parser. You can use comments to include explanatory remarks in a program.

If Syntax 1 is used, the parser ignores any text between the comment marker and the end of the line. If Syntax 2 is used, it ignores any text between the beginning and end markers.

Syntaxes 3 and 4 are used to support conditional compilation while retaining compatibility with browsers that do not support that feature. These browsers treat those forms of comments as syntaxes 1 and 2 respectively.


Comment Statements

Microsoft® JScript™
Comment Statements
See Also 		Language Reference

Conditional Compilation


@if Statement

Microsoft® JScript™
@if Statement
Language Reference
Version 3

See Also

Description
Conditionally executes a group of statements, depending on the value of an expression.
Syntax
@if (condition1)
text1
[@elif (condition2)
text2]
[else
text3]
@end

The @if statement syntax has these parts:

Part | Description
condition1, condition2 An expression that can be coerced into a Boolean expression.

text1 | Text to be parsed if condition1 is true.
text2 | Text to be parsed if condition1 is false and condition2 is true.
text3 | Text to be parsed if both condition1 and condition2 are false.

Remarks
When writing an @if statement, its clauses do not have to appear on separate lines. In addition, you may use multiple @elif clauses. If you do, all must come before an @else clause.

You commonly use the @if statement to determine which text among several options should be used for text output. For example:

alert(@if (@_win32) "using Windows NT or Windows 95" @else "using Windows 3.1" @end)


@if Statement

Microsoft® JScript™
@if Statement
See Also 		Language Reference

Conditional Compilation
Conditional Compilation Variables
@cc_on Statement
@set Statement


continue Statement

Microsoft® JScript™
continue Statement
Language Reference
Version 1

See Also

Description
Stops the current iteration of a loop, and starts a new iteration.
Syntax
continue [label];

The optional label argument specifies the statement to which continue applies.

Remarks
You can use the continue statement only inside a while, do...while, for, or for...in loop. Executing the continue statement stops the current iteration of the loop and continues program flow with the beginning of the loop. This has the following effects on the different types of loops:
  • while and do...while loops test their condition, and if true, execute the loop again.
  • for loops execute their increment expression, and if the test expression is true, execute the loop again.
  • for...in loops proceed to the next field of the specified variable and execute the loop again.


continue Statement

Microsoft® JScript™
continue Statement
See Also 		Language Reference

break Statement
do...while Statement
for Statement
for...in Statement
Labeled Statements
while Statement


do...while Statement

Microsoft® JScript™
do...while Statement 		Language Reference
Version 3

See Also

Description
Executes a statement block once, and then repeats execution of the loop until a condition expression evaluates to false.
Syntax
do
statement
while (expression) ;

The do...while statement syntax has these parts:

Part | Description
statement | The statement to be executed if expression is true. Can be a compound statement.
expression An expression that can be coerced to Boolean true or false. If expression is true, the loop is executed again. If expression is false, the loop is terminated.

Remarks
The value of expression is not checked until after the first iteration of the loop, guaranteeing that the the loop is executed at least once. Thereafter, it is checked after each succeeding iteration of the loop.


do...while Statement

Microsoft® JScript™
do...while Statement
See Also 		Language Reference

break Statement
continue Statement
for Statement
for...in Statement
while Statement
Labeled statements


for Statement

Microsoft® JScript™
for Statement
Language Reference
Version 1

See Also

Description
Executes a block of statements for as long as a specified condition is true.
Syntax
for (initialization; test; increment)
statement

The for statement syntax has these parts:

Part | Description
initialization | An expression. This expression is executed only once, before the loop is executed.
test | A Boolean expression. If test is true, statement is executed. If test if false, the loop is terminated.
increment | An expression. The increment expression is executed at the end of every pass through the loop.
statement | The statement to be executed if test is true. Can be a compound statement.

Remarks
You usually use a for loop when the loop is to be executed a specific number of times. The following example demonstrates one.
/* i is set to 0 at start, and is incremented by 1 at the end
of each iteration. Loop terminates when i is not less
than 10 before a loop iteration. */

for (i = 0; i < 10; i++)
{
  j *= i;
}


for Statement

Microsoft® JScript™
for Statement
See Also 		Language Reference

for...in Statement
while Statement


for...in Statement

Microsoft® JScript™
for...in Statement
Language Reference
Version 1

See Also

Description
Executes a statement for each element of an object or array.
Syntax
for (variable in [object | array])
statement

The for statement syntax has these parts:

Part | Description
variable A variable that can hold any of the elements of object.
object, array | An object or array over which to iterate.
statement | The statement to be executed for each member of object. Can be a compound statement.

Remarks
Before each iteration of a loop, variable is assigned the next element of object. You can then use it in any of the statements inside the loop exactly as if you were using the element of object.

When iterating over an object, there is no way to determine or control the order in which the members of the object are assigned to variable.


for...in Statement

Microsoft® JScript™
for...in Statement
See Also 		Language Reference

for Statement
while Statement


function Statement

Microsoft® JScript™
function Statement
Language Reference
Version 1

See Also

Description
Declares a new function.
Syntax

function functionname([argument1 [, argument2 [, ...argumentn]]])
{
statements
}

The function statement syntax has the following parts:

Part | Description
functionname | The name of the function.
argument1...argumentn | An optional, comma-separated list of arguments the function understands.
statements | One or more JScript statements.

Remarks

Use the function statement to declare a function for later use. The code contained in statements is not executed until the function is called from elsewhere in the script.


function Statement

Microsoft® JScript™
function Statement
See Also 		Language Reference

new Operator


if...else Statement

Microsoft® JScript™
if...else Statement
Language Reference
Version 1

See Also

Description
Conditionally executes a group of statements, depending on the value of an expression.
Syntax
if (condition)
statement1
[else
statement2]

The if...else statement syntax has these parts:

Part | Description
condition A Boolean expression. If condition is null or undefined, condition is treated as false.

statement1 | The statement to be executed if condition is true. Can be a compound statement.
statement2 | The statement to be executed if condition is false. Can be a compound statement.

Remarks
It is generally good practice to enclose statement1 and statement2 in braces ({}) for clarity and to avoid inadvertent errors. In the following example, you may intend that the else be used with the first if statement, but it is used with the second one.
if (x == 5)
  if (y == 6)
     z = 17;
else
  z = 20;
Changing the code in the following manner eliminates any ambiguities:
if (x == 5)
  {
  if (y == 6)
     z = 17;
  }
else
  z = 20;

Similarly, if you want to add a statement to statement1, and you don't use braces, you can accidentally create an error:

if (x == 5)
  z = 7;
  q = 42;
else
  z = 19;
In this case, there is a syntax error, as there is more than one statement between the if and else statements. Putting braces around the statements between the if and else is required.


if...else Statement

Microsoft® JScript™
if...else Statement
See Also 		Language Reference

Conditional Operator (?:)


Labeled Statement

Microsoft® JScript™
Labeled Statement 		Language Reference
Version 3

See Also

Description
Provides an identifier for a statement.
Syntax
label :
statement

Labeled statement syntax has these parts:

Part | Description
label A unique identifier used when referring to the labeled statement.
statement | The statement associated with label. May be a compound statement.

Remarks
Labels are used by the break and continue statements to specify the statement to which the break and continue apply.


Labeled Statement

Microsoft® JScript™
Labeled Statement
See Also 		Language Reference

break Statement
continue Statement


return Statement

Microsoft® JScript™
return Statement
Language Reference
Version 1

See Also

Description
Exits from the current function and returns a value from that function.
Syntax

return [expression];

The expression argument is the value to be returned from the function. If omitted, the function does not return a value.

Remarks
You use the return statement to stop execution of a function and return the value of expression. If expression is omitted, or no return statement is executed from within the function, the expression that called the current function is assigned the value undefined.


return Statement

Microsoft® JScript™
return Statement
See Also 		Language Reference

function Statement


@set Statement

Microsoft® JScript™
@set Statement 		Language Reference
Version 3

See Also

Description
Allows creation of variables used in conditional compilation statements.
Syntax
@set @varname = term

The @set statement syntax has these parts:

Part | Description
varname | Valid JScript variable name. Must be preceded by an "@" character at all times.
term | Zero or more unary operators followed by either a constant, conditional compilation variable, or parenthesized expression.

Remarks
Numeric and Boolean variables are supported for conditional compilation. Strings are not. Variables created using @set are generally used in conditional compilation statements, but can be used anywhere in JScript code.

Examples of variable declarations look like this:

@set @myvar1 = 12
@set @myvar2 = (@myvar1 * 20)
@set @myvar3 = @_jscript_version
The following operators are supported in parenthesized expressions:
  • ! ~
  • * / %
  • + -
  • << >> >>>
  • < <= > >=
  • == != === !==
  • & ^ |
  • && ||
If a variable is used before it has been defined, its value is NaN. NaN can be checked for using the @if statement:
@if (@newVar != @newVar)
  ...
This works because NaN is the only value not equal to itself.


@set Statement

Microsoft® JScript™
@set Statement
See Also 		Language Reference

Conditional Compilation
Conditional Compilation Variables
@cc_on Statement
@if Statement


switch Statement

Microsoft® JScript™
switch Statement 		Language Reference
Version 3

See Also

Description
Enables the execution of one or more statements when a specified expression's value matches a label.
Syntax
switch (expression) {
case label :
statementlist
case label :
statementlist
...
default :
statementlist
}

The switch statement syntax has these parts:

Part | Description
expression | The expression to be evaluated.
label | An identifier to be matched against expression. If label === expression, execution starts with the statementlist immediately after the colon. and continues until it encounters either a break statement, which is optional, or the end of the switch statement.
statementlist | One or more statements to be executed.

Remarks
Use the default clause to provide a statement to be executed if none of the label values matches expression. It can appear anywhere within the switch code block.

Zero or more label blocks may be specified. If no label matches the value of expression, and a default case is not supplied, no statements are executed.

Execution flows through a switch statement as follows:

  1. Evaluate expression and look at label in order until a match is found.
  2. If a label value equals expression, execute its accompanying statementlist.
    Continue execution until a break statement is encountered, or the switch statement ends. This means that multiple label blocks are executed if a break statement is not used.
  3. If no label equals expression, go to the default case. If there is no default case, go to last step.
  4. Continue execution at the statement following the end of the switch code block.
The following example tests an object for its type:
function MyObject() {
...}
switch (object.constructor){
    case Date:
    ...
    case Number:
    ...
    case String:
    ...
    case MyObject:
    ...
    default:
    ...
}


switch Statement

Microsoft® JScript™
switch Statement
See Also 		Language Reference

break Statement
if...else Statement


this Statement

Microsoft® JScript™
this Statement
Language Reference
Version 1

See Also

Description
Refers to the current object.
Syntax

this.property

Remarks

The this keyword is typically used in object constructors to refer to the current object. In the following example, this refers to the newly created Car object, and assigns values to three properties:

function Car(color, make, model)
{
  this.color = color;
  this.make = make;
  this.model = model;
}

For client versions of JScript, this refers to the window object if used outside of the context of any other object.


this Statement

Microsoft® JScript™
this Statement
See Also 		Language Reference

new Operator


var Statement

Microsoft® JScript™
var Statement
Language Reference
Version 1

See Also

Description
Declares a variable.
Syntax

var variable [ = value ] [, variable2 [ = value2], ...]

The var statement syntax has the following parts:

Part | Description
variable, variable2 | The names of the variables being declared.
value, value2 | The initial value assigned to the variable.

Remarks

Use the var statement to declare variables. These variables can be assigned values at declaration or later in your script. Examples of declaration follow:

var index;
var name = "Thomas Jefferson";
var answer = 42, counter, numpages = 10;


var Statement

Microsoft® JScript™
var Statement
See Also 		Language Reference

function Statement
new Operator


while Statement

Microsoft® JScript™
while Statement
Language Reference
Version 1

See Also

Description
Executes a statement until a specified condition is false.
Syntax
while (expression)
statement

The while statement syntax has these parts:

Part | Description
expression A Boolean expression checked before each iteration of the loop. If expression is true, the loop is executed. If expression is false, the loop is terminated.
statement | The statement to be executed if expression is true. Can be a compound statement.

Remarks
The while statement checks expression before a loop is first executed. If expression is false at this time, the loop is never executed.


while Statement

Microsoft® JScript™
while Statement
See Also 		Language Reference

break Statement
continue Statement
do...while Statement
for Statement
for...in Statement


with Statement

Microsoft® JScript™
with Statement
Language Reference
Version 1

See Also

Description
Establishes the default object for a statement.
Syntax

with (object)
statement

The with statement syntax has these parts:

Part | Description
object

The new default object.

statement | The statement for which object is the default object. Can be a compound statement.

Remarks
The with statement is commonly used to shorten the amount of code that you have to write in certain situations. In the example that follows, notice the repeated use of Math:
x = Math.cos(3 * Math.PI) + Math.sin(Math.LN10)
y = Math.tan(14 * Math.E)
When you use the with statement, your code becomes shorter and easier to read:
with (Math)
{
  x = cos(3 * PI) + sin (LN10)
  y = tan(14 * E)
}


with Statement

Microsoft® JScript™
with Statement
See Also 		Language Reference

this Statement


anchor Method

Microsoft® JScript™
anchor Method 		Language Reference
Version 1

See Also Applies To

Description

Places an HTML anchor with a NAME attribute around specified text in the object.
Syntax
strVariable.anchor(anchorstring)
"String Literal".anchor(anchorstring)

The anchorstring argument is text you want to place in the NAME attribute of an HTML anchor.

Remarks
Call the anchor method to create a named anchor out of a String object. The following example demonstrates how the anchor method accomplishes this:
var strVariable = "This is an anchor" ;
strVariable = strVariable.anchor("Anchor1");

The value of strVariable after the last statement is:

<A NAME="Anchor1">This is an anchor</A>

No checking is done to see if the tag has already been applied to the string.


anchor Method

Microsoft® JScript™
anchor Method
Applies To 		Language Reference

String Object


anchor Method

Microsoft® JScript™
anchor Method
See Also 		Language Reference

link Method
String Object Methods
String Object Properties


big Method

Microsoft® JScript™
big Method 		Language Reference
Version 1

See Also Applies To

Description

Places HTML <BIG> tags around text in a String object.
Syntax
strVariable.big( )
"String Literal".big( )
Remarks
The example that follows shows how the big method works:
var strVariable = "This is a string object";
strVariable = strVariable.big( );

The value of strVariable after the last statement is:

<BIG>This is a string object</BIG>

No checking is done to see if the tag has already been applied to the string.


big Method

Microsoft® JScript™
big Method
Applies To 		Language Reference

String Object


big Method

Microsoft® JScript™
big Method
See Also 		Language Reference

small Method
String Object Methods
String Object Properties


blink Method

Microsoft® JScript™
blink Method 		Language Reference
Version 1

See Also Applies To

Description
Places HTML <BLINK> tags around text in a String object.
Syntax
strVariable.blink( )
"String Literal".blink( )
Remarks
The example that follows demonstrates how the blink method works:
var strVariable = "This is a string object";
strVariable = strVariable.blink( );

The value of strVariable after the last statement is:

<BLINK>This is a string object</BLINK>

No checking is done to see if the tag has already been applied to the string.

The <BLINK> tag is not supported in Microsoft Internet Explorer.


blink Method

Microsoft® JScript™
blink Method
Applies To 		Language Reference

String Object


blink Method

Microsoft® JScript™
blink Method
See Also 		Language Reference

String Object Methods
String Object Properties


bold Method

Microsoft® JScript™
bold Method 		Language Reference
Version 1

See Also Applies To

Description
Places HTML <B> tags around text in a String object.
Syntax
strVariable.bold( )
"String Literal".bold( )
Remarks
The example that follows demonstrates how the bold method works:
var strVariable = "This is a string object";
strVariable = strVariable.bold( );

The value of strVariable after the last statement is:

<B>This is a string object</B>

No checking is done to see if the tag has already been applied to the string.


bold Method

Microsoft® JScript™
bold Method
Applies To 		Language Reference

String Object


bold Method

Microsoft® JScript™
bold Method
See Also 		Language Reference

italics Method
String Object Methods
String Object Properties


charAt Method

Microsoft® JScript™
charAt Method 		Language Reference
Version 1

See Also Applies To

Description

Retrieves the character at the index specified.
Syntax
strVariable.charAt(index)
"String Literal".charAt(index)

The index argument is the zero-based index of the desired character. Valid values are between 0 and the length of the string minus 1.

Remarks
The charAt method returns a character value equal to the character at the specified index. The first character in a string is at index 0, the second is at index 1, and so forth. Values of index out of valid range return undefined.


charAt Method

Microsoft® JScript™
charAt Method
Applies To 		Language Reference

String Object


charAt Method

Microsoft® JScript™
charAt Method
See Also 		Language Reference

String Object Methods
String Object Properties


charCodeAt Method

Microsoft® JScript™
charCodeAt Method 		Language Reference
Version 3

See Also Applies To

Description
Returns the Unicode encoding of the specified character.
Syntax
stringObj.charCodeAt(index)

The charCodeAt method syntax has these parts:

Part | Description
stringObj | Required. A String object or literal.
index | Required. The zero-based index of the specified character.

Remarks
If there is no character at the specified index, NaN is returned.


charCodeAt Method

Microsoft® JScript™
charCodeAt Method
Applies To 		Language Reference

String Object


charCodeAt Method

Microsoft® JScript™
charCodeAt Method
See Also 		Language Reference

fromCharCode Method
String Object Methods


concat Method (String)

Microsoft® JScript™
concat Method (String) 		Language Reference
Version 3

See Also Applies To

Description
Returns a String object containing the concatenation of two supplied strings.
Syntax
string1.concat(string2)

The concat method syntax has these parts:

Part | Description
string1 | Required. The String object or literal to concatenate with string2.
string2 | Required. A String object or literal to concatenate to the end of string1.

Remarks
The result of the concat method is equivalent to: result = string1 + string2.


concat Method (String)

Microsoft® JScript™
concat Method (String)
Applies To 		Language Reference

Array Object
String Object


concat Method (String)

Microsoft® JScript™
concat Method (String)
See Also 		Language Reference

Addition Operator (+)
concat Method (Array)
String Object Methods


fixed Method

Microsoft® JScript™
fixed Method 		Language Reference
Version 1

See Also Applies To

Description
Places HTML <TT> tags around text in a String object.
Syntax
strVariable.fixed( )
"String Literal".fixed( )
Remarks
The example that follows demonstrates how the fixed method works:
var strVariable = "This is a string object";
strVariable = strVariable.fixed( );

The value of strVariable after the last statement is:

<TT>This is a string object</TT>

No checking is done to see if the tag has already been applied to the string.


fixed Method

Microsoft® JScript™
fixed Method
Applies To 		Language Reference

String Object


fixed Method

Microsoft® JScript™
fixed Method
See Also 		Language Reference

String Object Methods
String Object Properties


fontcolor Method

Microsoft® JScript™
fontcolor Method 		Language Reference
Version 1

See Also Applies To

Description
Places an HTML <FONT> tag with the COLOR attribute around the text in a String object.
Syntax
strVariable.fontcolor(colorval)
"String Literal".fontcolor(colorval)

The colorval argument is a string containing a color value. This can either be the hexadecimal value for a color, or the predefined name for a color.

Remarks
The following example demonstrates the fontcolor method:
var strVariable = "This is a string";
strVariable = strVariable.fontcolor("red");

The value of strVariable after the last statement is:

<FONT COLOR="RED">This is a string</FONT>

Valid predefined color names depend on your JScript host (browser, server, and so forth). They may also vary from version to version of your host. Check your host documentation for more information.

No checking is done to see if the tag has already been applied to the string.


fontcolor Method

Microsoft® JScript™
fontcolor Method
Applies To 		Language Reference

String Object


fontcolor Method

Microsoft® JScript™
fontcolor Method
See Also 		Language Reference

fontsize Method
String Object Methods
String Object Properties


fontsize Method

Microsoft® JScript™
fontsize Method 		Language Reference
Version 1

See Also Applies To

Description
Places an HTML <FONT> tag with the SIZE attribute around the text in a String object.
Syntax
strVariable.fontsize(intSize)
"String Literal".fontsize(intSize)

The intSize argument is an integer value that determines the size of the text.

Remarks

The following example demonstrates the fontsize method:

var strVariable = "This is a string object"
strVariable.fontsize(-1)

The value of strVariable after the last statement is <FONT SIZE="-1">This is a string object</FONT>.

Valid integer values depend on your Microsoft JScript host. See your host documentation for more information.

No checking is done to see if the tag already exists.


fontsize Method

Microsoft® JScript™
fontsize Method
Applies To 		Language Reference

String Object


fontsize Method

Microsoft® JScript™
fontsize Method
See Also 		Language Reference

fontcolor Method
String Object Methods
String Object Properties


fromCharCode Method

Microsoft® JScript™
fromCharCode Method 		Language Reference
Version 3

See Also Applies To

Description
Creates a string from a number of Unicode character values.
Syntax
String.fromCharCode(code1, code2, ..., coden)

The code argument is the series of Unicode character values to convert into a string.

Remarks
A String object need not be created before calling fromCharCode.

In the following example, test contains the string "plain":

var test = String.fromCharCode(112, 108, 97, 105, 110);


fromCharCode Method

Microsoft® JScript™
fromCharCode Method
Applies To 		Language Reference

String Object


fromCharCode Method

Microsoft® JScript™
fromCharCode Method
See Also 		Language Reference

charCodeAt Method
String Object Methods


indexOf Method

Microsoft® JScript™
indexOf Method 		Language Reference
Version 1

See Also Applies To

Description
Finds the first occurrence a substring within a String object.
Syntax
strVariable.indexOf(substring, startindex)
"String Literal".indexOf(substring, startindex)

The indexOf method syntax has these arguments:

Part | Description
substring | The substring to search for within the String object.
startindex | An optional integer value specifying the index to begin searching within the String object. If omitted, searching begins at the beginning of the string.

Remarks
The indexOf method returns an integer value indicating the beginning of the substring within the String object. If the substring is not found, a -1 is returned.

If startindex is negative, startindex is treated as zero. If it is larger than the greatest character position index, it is treated as the largest possible index.

Searching is performed from left to right. Otherwise, this method is identical to lastIndexOf.


indexOf Method

Microsoft® JScript™
indexOf Method
Applies To 		Language Reference

String Object


indexOf Method

Microsoft® JScript™
indexOf Method
See Also 		Language Reference

lastIndexOf Method
String Object Methods
String Object Properties


italics Method

Microsoft® JScript™
italics Method 		Language Reference
Version 1

See Also Applies To

Description
Places HTML <I> tags around text in a String object.
Syntax
strVariable.italics( )
"String Literal".italics( )
Remarks
The example that follows demonstrates how the italics method works:
var strVariable = "This is a string";
strVariable = strVariable.italics( );

The value of strVariable after the last statement is:

<I>This is a string</I>

No checking is done to see if the tag has already been applied to the string.


italics Method

Microsoft® JScript™
italics Method
Applies To 		Language Reference

String Object


italics Method

Microsoft® JScript™
italics Method
See Also 		Language Reference

bold Method
String Object Methods
String Object Properties


lastIndexOf Method

Microsoft® JScript™
lastIndexOf Method 		Language Reference
Version 1

See Also Applies To

Description
Finds the last occurrence of a substring within a String object.
Syntax
strVariable.lastIndexOf(substring, startindex)
"String Literal".lastIndexOf(substring, startindex)

The lastIndexOf method syntax has these arguments:

Part | Description
substring | The substring to search for within the String object.
startindex | An optional integer value specifying the index to begin searching within the String object. If omitted, searching begins at the end of the string.

Remarks
The lastIndexOf method returns an integer value indicating the beginning of the substring within the String object. If the substring is not found, a -1 is returned.

If startindex is negative, startindex is treated as zero. If it is larger than the greatest character position index, it is treated as the largest possible index.

Searching is performed right to left. Otherwise, this method is identical to indexOf.


lastIndexOf Method

Microsoft® JScript™
lastIndexOf Method
Applies To 		Language Reference

String Object


lastIndexOf Method

Microsoft® JScript™
lastIndexOf Method
See Also 		Language Reference

indexOf Method
String Object Methods
String Object Properties


length Property (String)

Microsoft® JScript™
length Property (String) 		Language Reference
Version 1

See Also Applies To

Description
Contains the length of a String object.
Syntax
strVariable.length
"String Literal".length
Remarks
The length property contains an integer that indicates the number of characters in the String object. The last character in the String object has an index of length - 1.


length Property (String)

Microsoft® JScript™
length Property (String)
Applies To 		Language Reference

String Object


length Property (String)

Microsoft® JScript™
length Property (String)
See Also 		Language Reference

length Property (Array)
length Property (Function)
String Object Methods
String Object Properties


link Method

Microsoft® JScript™
link Method 		Language Reference
Version 1

See Also Applies To

Description
Places an HTML anchor with an HREF attribute around the text in a String object.
Syntax
strVariable.link(linkstring)
"String Literal".link(linkstring)

The linkstring argument is the text that you want to place in the HREF attribute of the HTML anchor.

Remarks
Call the link method to create a hyperlink out of a String object. The following is an example of how the method accomplishes this:
var strVariable = "This is a hyperlink";
strVariable = strVariable.link("http://www.microsoft.com");

The value of strVariable after the last statement is:

<A HREF="http://www.microsoft.com">This is a hyperlink</A>

No checking is done to see if the tag has already been applied to the string.


link Method

Microsoft® JScript™
link Method
Applies To 		Language Reference

String Object


link Method

Microsoft® JScript™
link Method
See Also 		Language Reference

anchor Method
String Object Methods
String Object Properties


match Method

Microsoft® JScript™
match Method 		Language Reference
Version 3

See Also Applies To

Description
Performs a search on a string using the supplied Regular Expression object.
Syntax
stringObj.match(rgExp)

The match method syntax has these parts:

Part | Description
stringObj | Required. The String object or literal on which to perform the search.
rgExp | Required. The regular expression to use in the search.

Remarks
The match method, which behaves like the exec method, returns an array of values.

Element zero of the array contains the last matched characters. Elements 1...n contain matches to any parenthesized substrings in the regular expression.

The method updates the contents of the RegExp object.


match Method

Microsoft® JScript™
match Method
Applies To 		Language Reference

String Object


match Method

Microsoft® JScript™
match Method
See Also 		Language Reference

exec Method
RegExp Object
replace Method
search Method
String Object Methods
test Method


replace Method

Microsoft® JScript™
replace Method 		Language Reference
Version 3

See Also Applies To

Description
Replaces the text found by a regular expression with other text.
Syntax
stringObj.match(rgExp, replaceText)

The replace method syntax has these parts:

Part | Description
stringObj | Required. The String object or literal on which to perform the replace. This object is not modified by the replace method.
rgExp | Required. A Regular Expression object describing what to search for.
replaceText | Required. A String object or literal containing the text to replace for every successful match of rgExp in stringObj.

Remarks
The result of the replace method is a copy of stringObj after all replacements have been made.

The method updates the contents of the RegExp object.


replace Method

Microsoft® JScript™
replace Method
Applies To 		Language Reference

String Object


replace Method

Microsoft® JScript™
replace Method
See Also 		Language Reference

exec Method
match Method
RegExp Object
search Method
String Object Methods
test Method


search Method

Microsoft® JScript™
search Method 		Language Reference
Version 3

See Also Applies To

Description
Searches a string for matches to a regular expression.
Syntax
stringObj.search(rgexp)

The search method syntax has these parts:

Part | Description
stringObj | Required. The String object or literal to search.
rgexp | Required. A Regular Expression object containing the pattern to search for.

Remarks
The search method indicates if a match is present or not. It returns true if a match is found, and false otherwise. To get further information, use the match method.


search Method

Microsoft® JScript™
search Method
Applies To 		Language Reference

String Object


search Method

Microsoft® JScript™
search Method
See Also 		Language Reference

exec Method
match Method
replace Method
String Object Methods
test Method


slice Method (String)

Microsoft® JScript™
slice Method (String) 		Language Reference
Version 3

See Also Applies To

Description
Returns a section of a string.
Syntax
stringObj.slice(start, [end])

The slice method syntax has these parts:

Part | Description
stringObj | Required. A String object or literal.
start | Required. The zero-based index of the beginning of the specified portion of stringObj.
end | Optional. The zero-based index of the end of the specified portion of stringObj. .

Remarks
The slice method returns a String object containing the specified portion of stringObj.

If negative, end indicates an offset from the end of stringObj. In addition, it is not zero-based. If omitted, extraction continues to the end of stringObj.

In the example that follows, the two uses of the slice method return the same thing. Negative one in the second example points to the last character in str1 as the ending point:

str1.slice(0)
str2.slice(0,-1)


slice Method (String)

Microsoft® JScript™
slice Method (String)
Applies To 		Language Reference

Array Object
String Object


slice Method (String)

Microsoft® JScript™
slice Method (String)
See Also 		Language Reference

slice Method (Array)
String Object Methods


small Method

Microsoft® JScript™
small Method 		Language Reference
Version 1

See Also Applies To

Description
Places HTML <SMALL> tags around text in a String object.
Syntax
strVariable.small( )
"String Literal".small( )
Remarks
The example that follows demonstrates how the small method works:
var strVariable = "This is a string";
strVariable = strVariable.small( );

The value of strVariable after the last statement is:

<SMALL>This is a string</SMALL>

No checking is done to see if the tag has already been applied to the string.


small Method

Microsoft® JScript™
small Method
Applies To 		Language Reference

String Object


small Method

Microsoft® JScript™
small Method
See Also 		Language Reference

big Method
String Object Methods
String Object Properties


split Method

Microsoft® JScript™
split Method 		Language Reference
Version 3

See Also Applies To

Description
Removes text from a string.
Syntax
stringObj.split(rgExp)

The split method syntax has these parts:

Part | Description
stringObj | Required. The String object or literal to remove text from. This object is not modified by the split method.
rgExp | Required. A Regular Expression object describing what to remove.

Remarks
The result of the split method is a copy of stringObj after all successful matches have been removed.

The method updates the RegExp object.


split Method

Microsoft® JScript™
split Method
Applies To 		Language Reference

String Object


split Method

Microsoft® JScript™
split Method
See Also 		Language Reference

concat Method
RegExp Object
Regular Expression Syntax
String Object Methods


strike Method

Microsoft® JScript™
strike Method 		Language Reference
Version 1

See Also Applies To

Description
Places HTML <STRIKE> tags around text in a String object.
Syntax
strVariable.strike( )
"String Literal".strike( )
Remarks
The example that follows demonstrates how the strike method works:
var strVariable = "This is a string object";
strVariable = strVariable.strike( );

The value of strVariable after the last statement is:

<STRIKE>This is a string object</STRIKE>

No checking is done to see if the tag has already been applied to the string.


strike Method

Microsoft® JScript™
strike Method
Applies To 		Language Reference

String Object


strike Method

Microsoft® JScript™
strike Method
See Also 		Language Reference

String Object Methods
String Object Properties


sub Method

Microsoft® JScript™
sub Method 		Language Reference
Version 1

See Also Applies To

Description
Places HTML <SUB> tags around text in a String object.
Syntax
strVariable.sub( )
"String Literal".sub( )
Remarks
The example that follows demonstrates how the sub method works:
var strVariable = "This is a string object"
strVariable = strVariable.sub( );

The value of strVariable after the last statement is:

<SUB>This is a string object</SUB>

No checking is done to see if the tag has already been applied to the string.


sub Method

Microsoft® JScript™
sub Method
Applies To 		Language Reference

String Object


sub Method

Microsoft® JScript™
sub Method
See Also 		Language Reference

String Object Methods
String Object Properties
sup Method


substr Method

Microsoft® JScript™
substr Method 		Language Reference
Version 3

See Also Applies To

Description
Returns a substring beginning at a specified location and having a specified length.
Syntax
stringvar.substr(start [, length ])

The substr method syntax has these parts:

Part | Description
stringvar | Required. A string literal or String object from which the substring is extracted.
start | Required. The starting position of the desired substring. The index of the first character in the string is zero.
length | Optional. The number of characters to include in the returned substring.

Remarks
If length is zero or negative, an empty string is returned. If not specified, the substring continues to the end of stringvar.


substr Method

Microsoft® JScript™
substr Method
Applies To 		Language Reference

String Object


substr Method

Microsoft® JScript™
substr Method
See Also 		Language Reference

String Object Methods
String Object Properties
substring Method


substring Method

Microsoft® JScript™
substring Method 		Language Reference
Version 1

See Also Applies To

Description
Retrieves the substring at the specified location within a String object.
Syntax
strVariable.substring(start, end)
"String Literal".substring(start, end)

The substring method syntax has these arguments:

Part | Description
start | The zero-based index indicating the beginning of the substring.
end | The zero-based index indicating the end of the substring.

Remarks
The substring method returns a String object containing the substring derived from the original object.

The substring method uses the lower of start and end as the beginning point of the substring. For example, strvar.substring(0, 3) and strvar.substring(3, 0) return the same substring.

The only exception to this is for negative parameters. If the first parameter is less than zero, it is treated as zero. If the second parameter is negative, it is set to the value of the first parameter.

The length of the substring is equal to the absolute value of the difference between start and end. For example, the length of the substring returned in strvar.substring(0, 3) and strvar.substring(3, 0) is three.

Finally, start and end can be strings. If so, these strings are coerced into integers if possible. If not, the value of the parameter is treated as zero.


substring Method

Microsoft® JScript™
substring Method
Applies To 		Language Reference

String Object


substring Method

Microsoft® JScript™
substring Method
See Also 		Language Reference

String Object Methods
String Object Properties
substr Method


sup Method

Microsoft® JScript™
sup Method 		Language Reference
Version 1

See Also Applies To

Description
Places HTML <SUP> tags around text in a String object.
Syntax
strVariable.sup( )
"String Literal".sup( )
Remarks
The example that follows demonstrates how the sup method works:
var strVariable = "This is a string object";
strVariable = strVariable.sup( );

The value of strVariable after the last statement is:

<SUP>This is a string object</SUP>

No checking is done to see if the tag has already been applied to the string.


sup Method

Microsoft® JScript™
sup Method
Applies To 		Language Reference

String Object


sup Method

Microsoft® JScript™
sup Method
See Also 		Language Reference

String Object Methods
String Object Properties
sub Method


toLowerCase Method

Microsoft® JScript™
toLowerCase Method 		Language Reference
Version 1

See Also Applies To

Description
Places the text in a String object in lowercase characters.
Syntax
strVariable.toLowerCase( )
"String Literal".toLowerCase( )
Remarks
The toLowerCase method has no effect on nonalphabetic characters.

The following example demonstrates the effects of the toLowerCase method:

var strVariable = "This is a STRING object";
strVariable = strVariable.toLowerCase( );

The value of strVariable after the last statement is:

this is a string object


toLowerCase Method

Microsoft® JScript™
toLowerCase Method
Applies To 		Language Reference

String Object


toLowerCase Method

Microsoft® JScript™
toLowerCase Method
See Also 		Language Reference

String Object Methods
String Object Properties
toUpperCase Method


toUpperCase Method

Microsoft® JScript™
toUpperCase Method 		Language Reference
Version 1

See Also Applies To

Description
Places the text in a String object in uppercase characters.
Syntax
strVariable.toUpperCase( )
"String Literal".toUpperCase( )
Remarks

The toUpperCase method has no effect on nonalphabetic characters.

The following example demonstrates the effects of the toUpperCase method:

var strVariable = "This is a STRING object";
strVariable = strVariable.toUpperCase( );

The value of strVariable after the last statement is:

THIS IS A STRING OBJECT


toUpperCase Method

Microsoft® JScript™
toUpperCase Method
Applies To 		Language Reference

String Object


toUpperCase Method

Microsoft® JScript™
toUpperCase Method
See Also 		Language Reference

String Object Methods
String Object Properties
toLowerCase Method


AtEndOfLine Property

Microsoft® JScript™
AtEndOfLine Property 		Language Reference
Version 2

See Also Applies To

Description
Returns true if the file pointer is positioned immediately before the end-of-line marker in a TextStream file; false if it is not. Read-only.
Syntax
object.AtEndOfLine

The object is always the name of a TextStream object.

Remarks
The AtEndOfLine property applies only to TextStream files that are open for reading; otherwise, an error occurs.

The following code illustrates the use of the AtEndOfLine property:

function GetALine(filespec)
{
    var fs, a, s, ForReading;
    ForReading = 1, s = "";
    fs = new ActiveXObject("Scripting.FileSystemObject");
    a = fs.OpenTextFile(filespec, ForReading, false);
    while (!a.AtEndOfLine)
    {
        s += a.Read(1);
    }
    a.Close( );
    return s;
}


AtEndOfLine Property

Microsoft® JScript™
AtEndOfLine Property
Applies To 		Language Reference

TextStream Object


AtEndOfLine Property

Microsoft® JScript™
AtEndOfLine Property
See Also 		Language Reference

AtEndOfStream Property


AtEndOfStream Property

Microsoft® JScript™
AtEndOfStream Property 		Language Reference
Version 2

See Also Applies To

Description
Returns true if the file pointer is at the end of a TextStream file; false if it is not. Read-only.
Syntax
object.AtEndOfStream

The object is always the name of a TextStream object.

Remarks
The AtEndOfStream property applies only to TextStream files that are open for reading, otherwise, an error occurs.

The following code illustrates the use of the AtEndOfStream property:

function GetALine(filespec)
{
    var fs, f, s, ForReading;
    ForReading = 1, s = "";
    fs = new ActiveXObject("Scripting.FileSystemObject");
    f = fs.OpenTextFile(filespec, ForReading, false);
    while (!f.AtEndOfStream)
        s += f.ReadLine( );
    f.Close( );
    return s;
}


AtEndOfStream Property

Microsoft® JScript™
AtEndOfStream Property
Applies To 		Language Reference

TextStream Object


AtEndOfStream Property

Microsoft® JScript™
AtEndOfStream Property
See Also 		Language Reference

AtEndOfLine Property


Close Method

Microsoft® JScript™
Close Method 		Language Reference
Version 2

See Also Applies To

Description
Closes an open TextStream file.

Syntax
object.Close( );

The object is always the name of a TextStream object.


Close Method

Microsoft® JScript™
Close Method
Applies To 		Language Reference

TextStream Object


Close Method

Microsoft® JScript™
Close Method
See Also 		Language Reference

Read Method
Write Method


Column Property

Microsoft® JScript™
Column Property 		Language Reference
Version 2

See Also Applies To

Description
Read-only property that returns the column number of the current character position in a TextStream file.

Syntax
object.Column

The object is always the name of a TextStream object.

Remarks
After a newline character has been written, but before any other character is written, Column is equal to 1.


Column Property

Microsoft® JScript™
Column Property
Applies To 		Language Reference

TextStream Object


Column Property

Microsoft® JScript™
Column Property
See Also 		Language Reference

Line Property


Line Property

Microsoft® JScript™
Line Property 		Language Reference
Version 2

See Also Applies To

Description
Read-only property that returns the current line number in a TextStream file.

Syntax
object.Line

The object is always the name of a TextStream object.

Remarks
After a file is initially opened and before anything is written, Line is equal to 1.


Line Property

Microsoft® JScript™
Line Property
Applies To 		Language Reference

TextStream Object


Line Property

Microsoft® JScript™
Line Property
See Also 		Language Reference

Column Property


Read Method

Microsoft® JScript™
Read Method 		Language Reference
Version 2

See Also Applies To

Description
Reads a specified number of characters from a TextStream file and returns the resulting string.

Syntax
object.Read(characters)

The Read method syntax has these parts:

Part | Description
object | Required. Always the name of a TextStream object.
characters | Required. Number of characters you want to read from the file.


Read Method

Microsoft® JScript™
Read Method
Applies To 		Language Reference

TextStream Object


ReadAll Method

Microsoft® JScript™
ReadAll Method 		Language Reference
Version 2

See Also Applies To

Description
Reads an entire TextStream file and returns the resulting string.

Syntax
object.ReadAll( );

The object is always the name of a TextStream object.


ReadAll Method

Microsoft® JScript™
ReadAll Method
Applies To 		Language Reference

TextStream Object


ReadAll Method

Microsoft® JScript™
ReadAll Method
See Also 		Language Reference

Read Method
ReadLine Method
Skip Method
SkipLine Method


Read Method

Microsoft® JScript™
Read Method
See Also 		Language Reference

ReadAll Method
ReadLine Method
Skip Method
SkipLine Method


ReadLine Method

Microsoft® JScript™
ReadLine Method 		Language Reference
Version 2

See Also Applies To

Description
Reads an entire line (up to, but not including, the newline character) from a TextStream file and returns the resulting string.

Syntax
object.ReadLine( )

The object argument is always the name of a TextStream object.


ReadLine Method

Microsoft® JScript™
ReadLine Method
Applies To 		Language Reference

TextStream Object


ReadLine Method

Microsoft® JScript™
ReadLine Method
See Also 		Language Reference

Read Method
ReadAll Method
Skip Method
SkipLine Method


Skip Method

Microsoft® JScript™
Skip Method 		Language Reference
Version 2

See Also Applies To

Description
Skips a specified number of characters when reading a TextStream file.

Syntax
object.Skip(characters)

The Skip method syntax has these parts:

Part | Description
object | Required. Always the name of a TextStream object.
characters | Required. Number of characters to skip when reading a file.

Remarks
Skipped characters are discarded.


Skip Method

Microsoft® JScript™
Skip Method
Applies To 		Language Reference

TextStream Object


Skip Method

Microsoft® JScript™
Skip Method
See Also 		Language Reference

Close Method
Read Method
ReadAll Method
ReadLine Method
SkipLine Method
Write Method
WriteLine Method
WriteBlankLines Method


SkipLine Method

Microsoft® JScript™
SkipLine Method 		Language Reference
Version 2

See Also Applies To

Description
Skips the next line when reading a TextStream file.

Syntax
object.SkipLine( )

The object is always the name of a TextStream object.


SkipLine Method

Microsoft® JScript™
SkipLine Method
Applies To 		Language Reference

TextStream Object


SkipLine Method

Microsoft® JScript™
SkipLine Method
See Also 		Language Reference

Read Method
ReadAll Method
ReadLine Method
Skip Method


Write Method

Microsoft® JScript™
Write Method 		Language Reference
Version 2

See Also Applies To

Description
Writes a specified string to a TextStream file.

Syntax
object.Write(string)

The Write method syntax has these parts:

Part | Description
object | Required. Always the name of a TextStream object.
string | Required. The text you want to write to the file.

Remarks
Specified strings are written to the file with no intervening spaces or characters between each string. Use the WriteLine method to write a newline character or a string that ends with a newline character.


Write Method

Microsoft® JScript™
Write Method
Applies To 		Language Reference

TextStream Object


WriteBlankLines Method

Microsoft® JScript™
WriteBlankLines Method 		Language Reference
Version 2

See Also Applies To

Description
Writes a specified number of newline characters to a TextStream file.

Syntax
object.WriteBlankLines(lines)

The WriteBlankLines method syntax has these parts:

Part | Description
object | Required. Always the name of a TextStream object.
lines | Required. Number of newline characters you want to write to the file.


WriteBlankLines Method

Microsoft® JScript™
WriteBlankLines Method
Applies To 		Language Reference

TextStream Object


WriteBlankLines Method

Microsoft® JScript™
WriteBlankLines Method
See Also 		Language Reference

Write Method
WriteLine Method


Write Method

Microsoft® JScript™
Write Method
See Also 		Language Reference

WriteBlankLines Method
WriteLine Method


WriteLine Method

Microsoft® JScript™
WriteLine Method 		Language Reference
Version 2

See Also Applies To

Description
Writes a specified string and newline character to a TextStream file.

Syntax
object.WriteLine([string])

The WriteLine method syntax has these parts:

Part | Description
object | Required. Always the name of a TextStream object.
string | Optional. The text you want to write to the file. If omitted, a newline character is written to the file.


WriteLine Method

Microsoft® JScript™
WriteLine Method
Applies To 		Language Reference

TextStream Object


WriteLine Method

Microsoft® JScript™
WriteLine Method
See Also 		Language Reference

Write Method
WriteBlankLines Method


Data Type Conversion

Microsoft® JScript™
Data Type Conversion 		Language Reference
Version 3

Description
Microsoft JScript provides automatic type conversion as the context may require. This means that if the context expects a value to be a string, for example, JScript tries to convert the value to a string.

The language has six types of data. All values have one of these types:

undefined
The undefined type has one value only, undefined.
Null
The null type has one value only, null.
Boolean
The Boolean type represents the two logical values, true and false.
String
Strings, delineated by single or double quotation marks, contain zero or more unicode characters. An empty string ("") has zero characters and length.
Number
Numbers can be integers or floating point numbers according to the IEEE 754 specification. There also several special values:
  • NaN, or not a Number
  • Positive Infinity
  • Negative Infinity
  • Positive zero
  • Negative zero
Object
An Object type is an object definition including its set of properties and methods.
The following table defines what happens when the context requires that JScript convert one data type into another:

Output Data Type | Input Data Type
Undefined | Null | Boolean | Number | String | Object
boolean | false | false | no conversion | false if +0, -0, or NaN; otherwise true | false if empty string (""); otherwise true | true
number | NaN | NaN | 1 if true; +0 if false | no conversion | If it cannot be interpreted as a number, it is interpreted as NaN | Number object
string "undefined" "null" "true" or "false" The absolute value of the number plus its sign, with the following exceptions:
  • NaN returns "NaN"
  • +0 or -0 returns "0"
  • + infinity returns "Infinity"
  • - infinity returns "-Infinity"
            • no conversion String object
    object | runtime error | runtime error | New Boolean object | New Number object | New String object | no conversion


dimensions Method

Microsoft® JScript™
dimensions Method 		Language Reference
Version 3

See Also Applies To

Description
Returns the number of dimensions in a VBArray.
Syntax
array.dimensions( )

The array argument is a VBArray object.

Remarks
The dimensions method provides a way to retrieve the number of dimensions in a specified VBArray.


dimensions Method

Microsoft® JScript™
dimensions Method
Applies To 		Language Reference

VBArray Object


dimensions Method

Microsoft® JScript™
dimensions Method
See Also 		Language Reference

getItem Method
lbound Method
toArray Method
ubound Method


getItem Method

Microsoft® JScript™
getItem Method 		Language Reference
Version 3

See Also Applies To

Description
Retrieves the item at the specified location.
Syntax
safeArray.getItem(dimension1[, dimension2, ...], dimensionn)

The getItem method syntax has these parts:

Part | Description
safeArray | Required. A VBArray object.
dimension1, ..., dimensionn | Specifies the exact location of the desired element of the VBArray. n equals the number of dimensions in the VBArray.


getItem Method

Microsoft® JScript™
getItem Method
Applies To 		Language Reference

VBArray Object


getItem Method

Microsoft® JScript™
getItem Method
See Also 		Language Reference

dimensions Method
lbound Method
toArray Method
ubound Method


lbound Method

Microsoft® JScript™
lbound Method 		Language Reference
Version 3

See Also Applies To

Description
Returns the lowest index value used in the specified dimension of a VBArray.
Syntax
safeArray.lbound(dimension)

The lbound method syntax has these parts:

Part | Description
safeArray | Required. A VBArray object.
dimension | Optional. The dimension of the VBArray for which the lower bound index is wanted. If omitted, lbound behaves as if a 1 was passed.

Remarks
If the VBArray is empty, the lbound method returns undefined. If dimension is greater than the number of dimensions in the VBArray, or is negative, the method generates a "Subscript out of range" error.


lbound Method

Microsoft® JScript™
lbound Method
Applies To 		Language Reference

VBArray Object


lbound Method

Microsoft® JScript™
lbound Method
See Also 		Language Reference

dimensions Method
getItem Method
toArray Method
ubound Method


toArray Method

Microsoft® JScript™
toArray Method 		Language Reference
Version 3

See Also Applies To

Description
Converts a VBArray to a standard JScript array.
Syntax
safeArray.toArray( )

The safeArray argument is a VBArray object.

Remarks
The conversion translates the multidimensional VBArray into a single dimensional JScript array. Each successive dimension is appended to the end of the previous one. For example, a VBArray with three dimensions and three elements in each dimension is converted into a JScript array as follows

Suppose the VBArray contains: (1, 2, 3), (4, 5, 6), (7, 8, 9). After translation, the JScript array contains: 1, 2, 3, 4, 5, 6, 7, 8, 9.

There is currently no way to convert a JScript array into a VBArray.


toArray Method

Microsoft® JScript™
toArray Method
Applies To 		Language Reference

VBArray Object


toArray Method

Microsoft® JScript™
toArray Method
See Also 		Language Reference

dimensions Method
getItem Method
lbound Method
ubound Method


ubound Method

Microsoft® JScript™
ubound Method 		Language Reference
Version 3

See Also Applies To

Description
Returns the highest index value used in the specified dimension of the VBArray.
Syntax
safeArray.ubound(dimension)

The ubound method syntax has these parts:

Part | Description
safeArray | Required. A VBArray object.
dimension | Optional. The dimension of the VBArray for which the higher bound index is wanted. If omitted, ubound behaves as if a 1 was passed.

Remarks
If the VBArray is empty, the ubound method returns undefined. If dim is greater than the number of dimensions in the VBArray, or is negative, the method generates a "Subscript out of range" error.


ubound Method

Microsoft® JScript™
ubound Method
Applies To 		Language Reference

VBArray Object


ubound Method

Microsoft® JScript™
ubound Method
See Also 		Language Reference

dimensions Method
getItem Method
lbound Method
toArray Method


Version Information

Microsoft® JScript™
Version Information 		Language Reference

The following table lists the version of Microsoft JScript implemented by host applications.

Host | JScript Version 1.0 | JScript Version 2.0 | JScript Version 3.0
Microsoft Internet Explorer 3.0 | X
Microsoft Internet Information Server 1.0 | X
Microsoft Internet Explorer 4.0 | x
Microsoft Internet Information Server 4.0 | x
Microsoft Windows Scripting Host 1.0 | x
Microsoft Outlook 98 | x


JScript Objects

Microsoft® JScript™
JScript Objects
JScript Tutorial
Previous
Next

What Are Objects?
In Microsoft JScript, objects are, essentially, collections of properties and methods. A method is a function that is a member of an object, and a property is a value or set of values (in the form of an array or object) that is a member of an object. JScript supports three kinds of objects: intrinsic objects, objects you create, and browser objects, which are covered elsewhere.

Objects as Arrays
In JScript, objects and arrays are handled identically. You can refer to any of the members of an object (its properties and methods) either by name (using the name of the object, followed by a period, followed by the name of the property) or by its array subscript index. Subscript numbering in JScript begins with 0. For convenience, the subscript can also be referred to by its name.

Thus, a property can be referred to in several ways. All of the following statements are equivalent.

theWidth = spaghetti.width;
theWidth = spaghetti[3];  // [3] is the "width" index.
theWidth = spaghetti["width"];
While it is possible to use brackets to refer to a property by its numeric index, it is not possible to use the dot (.) convention with index numbers. The following statement generates an error.

theWidth = spaghetti.3;
When an object has another object as a property, the naming convention extends in a straightforward way.

var init4 = toDoToday.shoppingList[3].substring(0,1);  // shoppingList, an array, is a property of toDoToday.
The fact that objects can have other objects as properties lets you generate arrays with more than one subscript, which are not directly supported. The following code creates a multiplication table for values from 0 times 0 through 16 times 16.

var multTable = new Array(17);  // Make the shell that will become the table.
for (var j = 0; j < multTable.length; j++)  {  // Prepare to fill it with rows.
    var aRow = new Array(17);  // Create a row.
    for (var i = 0; i < aRow.length; i++)  {  // Prepare to fill the row.
    aRow[i] = (i + " times " + j + " = " + i*j);  // Make and place one value.
    }
multTable[j] = aRow;  // Put the filled row into the table.
}
To refer to one of the elements of an array of this kind, use multiple sets of brackets.
var multiply3x7 = multTable[3][7];
The following statement generates an error.
var multiply3x7 = multTable[3, 7];


Recursion

Microsoft® JScript™
Recursion
 JScript Tutorial
Previous
Next

Recursion is an important programming technique. It's used to have a function call itself from within itself. One handy example is the calculation of factorials. The factorials of 0 and 1 are both defined specifically to be 1. The factorials of larger numbers are calculated by multiplying 1 * 2 * ..., incrementing by 1 until you reach the number for which you're calculating the factorial.

The following paragraph is a function, defined in words, that calculates a factorial.

"If the number is less than zero, reject it. If it isn't an integer, round it down to the next integer. If the number is zero or one, its factorial is one. If the number is larger than one, multiply it by the factorial of the next smaller number."

To calculate the factorial of any number that is larger than 1, you need to calculate the factorial of at least one other number. The function you use to do that is the function you're in the middle of already; the function must call itself for the next smaller number, before it can execute on the current number. This is an example of recursion.

Clearly, there is a way to get in trouble here. You can easily create a recursive function that doesn't ever get to a definite result, and cannot reach an endpoint. Such a recursion causes the computer to execute a so-called "infinite" loop. Here's an example: omit the first rule (the one about negative numbers) from the verbal description of calculating a factorial, and try to calculate the factorial of any negative number. This fails, because in order to calculate the factorial of, say, -24 you first have to calculate the factorial of -25; but in order to do that you first have to calculate the factorial of -26; and so on. Obviously, this never reaches a stopping place.

Thus, it is extremely important to design recursive functions with great care. If you even suspect that there's any chance of an infinite recursion, you can have the function count the number of times it calls itself, and thus make sure that if the function calls itself too many times, however many you decide that should be, it automatically quits.

Here's the factorial function again, this time written in JScript code.

function factorial(aNumber)  {
aNumber = Math.floor(aNumber);  // If the number is not an integer, round it down.
if (aNumber < 0)  {  // If the number is less than zero, reject it.
    return "not a defined quantity";
    }
      if ((anumber == 0) || (anumber == 1))  {  // If the number is 0 or 1, its factorial is 1.
      return 1;
      }
        else return (anumber * factorial(anumber - 1));  // Otherwise, recurse until done.
}


Variable Scope

Microsoft® JScript™
Variable Scope
 JScript Tutorial
Previous
Next

Microsoft JScript has two scopes: global and local. If you declare a variable outside of any function definition, it is a global variable, and its value is accessible and modifiable throughout your program. If you declare a variable inside of a function definition, that variable is local. It is created and destroyed every time the function is executed; it cannot be accessed by anything outside the function.

A local variable can have the same name as a global variable, but it is entirely distinct and separate. Consequently, changing the value of one variable has no effect on the other. Inside the function in which the local variable is declared, only the local version has meaning.

var aCentaur = "a horse with rider,";  // Global definition of aCentaur.

// JScript code, omitted for brevity.
function antiquities()  // A local aCentaur variable is declared in this function.
{

// JScript code, omitted for brevity.
var aCentaur = "A centaur is probably a mounted Scythian warrior";

// JScript code, omitted for brevity.
  aCentaur += ", misreported; that is, ";  // Adds to the local variable.

// JScript code, omitted for brevity.
}  // End of the function.

var nothinginparticular = antiquities();
aCentaur += " as seen from a distance by a naive innocent.";

/*
Within the function, the variable contains "A centaur is probably a mounted Scythian warrior,
misreported; that is, "; outside the function, the variable contains the rest of the sentence:
"a horse with rider, as seen from a distance by a naive innocent."
*/
It's important to note that variables act as if they were declared at the beginning of whatever scope they exist in. Sometimes this results in unexpected behaviors.

var aNumber = 100;
var withAdditive = 0;

withAdditive += aNumber;  // withAdditive is now 100.
tweak();
withAdditive += aNumber;  // withAdditive is now 200.

function tweak()  {
var newThing = 0;  // Explicit declaration of the newThing variable.
// The next statement, if it were not commented out, would generate an error.
// newThing = aNumber;
// The next statement assigns the value 42 to the local aNumber, implicitly declaring it.
aNumber = 42;
if (false)  {
    var aNumber;  // This statement is never executed.
    aNumber = "Hello!";  // This statement is never executed.
    }  // End of the conditional.
}  // End of the function definition.
The statement that is commented out attempts to assign the value of the local variable aNumber to the local variable newThing. It fails, despite the fact that a local aNumber variable is defined elsewhere in the function, and therefore exists throughout. The aNumber variable does not have any assigned value at the point where this statement occurs in the code, and is thus undefined.


Special Characters
JScript Tutorial
Previous
Next

Special Characters
JScript provides special characters that allow you to include in strings some characters you can't type directly. Each of these characters begins with a backslash. The backslash is an escape character you use to inform the JScript interpreter that the next character is special.

Escape Sequence | Character
\b | Backspace
\f | Form feed
\n | Line feed (newline)
\r | Carriage return
\t | Horizontal tab (Ctrl-I)
\' Single quotation mark
\" Double quotation mark
\\ Backslash

Notice that because the backslash itself is used as the escape character, you cannot directly type a one in your script. If you want to write a backslash, you must type two of them together (\\).

document.write('The image path is C:\\webstuff\\mypage\\gifs\\garden.gif.');
document.write('The caption reads, "After the snow of \'97. Grandma\'s house is covered."');
You can use these escape sequences to control formatting of text inside <PRE> and <XMP> tags and, to some extent, inside alert, prompt, and confirm message boxes.


Writing JScript Code

Microsoft® JScript™
Writing JScript Code
JScript Tutorial
Previous
Next

Like many other programming languages, Microsoft JScript is written in text format, and is organized into statements, blocks consisting of related sets of statements, and comments. Within a statement you can use variables, immediate data such as strings and numbers, and expressions.

Statements
A JScript code statement consists of one or more items and symbols on a line. A new line begins a new statement, but it is a good idea to terminate your statements explicitly. You can do this with the semicolon (;), which is the JScript termination character.

aBird = "Robin";
var today = new Date();
A group of JScript statements that is surrounded by braces is called a block. Blocks of statements are used, for example, in functions and conditionals. In the following example, the first statement begins the definition of a function, which consists of a block of five statements. The last three statements, which are not surrounded by braces, are not a block and are not part of the function definition.

function convert(inches)  {
    feet = inches / 12;  //  These five statements are in a block.
    miles = feet / 5280;
    nauticalMiles = feet / 6080;
    cm = inches * 2.54;
    meters = inches / 39.37;
}
km = meters / 1000;  //  These three statements are not in a block.
kradius = km;
mradius = miles;
Comments
A single-line JScript comment begins with a pair of forward slashes (//). A multiline comment begins with a forward slash and asterisk in combination (/*), and ends with the reverse (*/).

aGoodIdea = "Comment your code thoroughly.";  //  This is a single-line comment.

/*
This is a multiline comment that explains the preceding code statement.

The statement assigns a value to the aGoodIdea variable. The value, which is contained
between the quote marks, is called a literal. A literal explicitly and directly contains
information; it does not refer to the information indirectly. (The quote marks are not
part of the literal.)
*/

//  This is another multiline comment, written as a series of single-line comments.
//  After the statement is executed, you can refer to the content of the aGoodIdea
//  variable by using its name, as in the next statement, in which a string literal is
//  appended to the aGoodIdea variable by concatenation to create a new variable.

var extendedIdea = aGoodIdea + " You never know when you'll have to figure out what it does.";
Assignments and Equality
The equal sign (=) is used in JScript to indicate the action of assigning a value. That is, a JScript code statement could say

anInteger = 3;
It means "Assign the value 3 to the variable anInteger," or "anInteger takes the value 3." When you want to compare two values to find out whether they are equal, use a pair of equal signs (==). This is discussed in detail in Controlling Program Flow.

Expressions
A JScript expression is something that a person can read as a Boolean or numeric expression. Expressions contain symbol characters like "+" rather than words like "added to". Any valid combination of values, variables, operators, and expressions constitutes an expression.

var anExpression = "3 * (4 / 5)";
var aSecondExpression = "Math.PI * radius * 2";
var aThirdExpression = aSecondExpression + "%" + anExpression;
var aFourthExpression = "(" + aSecondExpression + ") % (" + anExpression + ")";


Using Arrays

Microsoft® JScript™
Using Arrays
 JScript Tutorial
Previous
Next

Array Indexing
Arrays in JScript are sparse. That is, if you have an array with three elements that are numbered 0, 1, and 2, you can create element 50 without worrying about elements 3 through 49. If the array has an automatic length variable (see Intrinsic Objects for an explanation of automatic monitoring of array length), the length variable is set to 51, rather than to 4. You can certainly create arrays in which there are no gaps in the numbering of elements, but you aren't required to. In fact, in JScript, your arrays don't have to have numbered subscripts at all.

In JScript, objects and arrays are essentially identical to each other. The real difference is not in the data, but rather in the way you address the members of an array or the properties and methods of an object.

Addressing Arrays
There are two main ways to address the members of an array. Ordinarily, you address arrays by using brackets. The brackets enclose either a numeric value or an expression that evaluates to a nonnegative integer. The following example assumes that the entryNum variable is defined and assigned a value elsewhere in the script.

theListing = addressBook[entryNum];
theFirstLine = theListing[1];
This method of addressing is equivalent to the method for addressing objects, though in object addressing, what follows the period must be the name of an actual property. If there is no such property, your code generates an error.

The second way to address an array is to make an object/array that contains properties that are numbered, and then generate the numbers in a loop. The following example generates two arrays, one for the name and one for the address, from a listing in addressBook. Each of these contains four properties. An instance of theName, for example, built from the [Name1] through [Name4] properties of theListing, might contain "G." "Edward" "Heatherington" "IV", or "George" "" "Sand" "".

theListing = addressBook[entryNum];
for (i = 1; i < 4; i++)  {
theName[i] = theListing["Name" + i];
theAddress[i] = theListing["Address" + i];
}
While this particular instance is short, and could easily have been written in the "dot" style of notation, (that is, addressing theListing, theName, and theAddress as objects rather than as arrays), that is not always possible. Sometimes the particular property may not exist until run time, or there may be no way to know which one it will be in advance. For example, if the addressBook array were arranged by last name instead of by numbered listings, the user would probably be entering names "on the fly," while the script is running, to look people up. The following example assumes the existence of appropriate function definitions elsewhere in the script.

theListing = addressBook[getName()];
theIndivListing = theListing[getFirstName()];
This is associative addressing of the array, that is, addressing by means of fully arbitrary strings. Objects in JScript are actually associative arrays. Although you can (and frequently do) use the "dot" style of addressing, you are not by any means required to.


Copying, Passing, and Comparing Data

Microsoft® JScript™
Copying, Passing, and Comparing Data
 JScript Tutorial
Previous
Next

In Microsoft JScript, how data is handled depends on its data type.
By Value vs. By Reference
Numbers and Boolean values (true and false) are copied, passed, and compared by value. When you copy or pass by value, you allocate a space in computer memory and put the value of the original into it. If you then change the original, the copy is not affected (and vice versa), because the two are separate entities.

Objects, arrays, and functions are copied, passed, and compared by reference under most circumstances. When you copy or pass by reference, you essentially create a pointer to the original item, and use the pointer as if it were a copy. If you then change the original you change both it and the copy (and vice versa). There is really only one entity; the "copy" is not actually a copy, it's just another reference to the data.

Note You can change this behavior for objects and arrays by specifying the assign( ) method for them.
Last, strings are copied and passed by reference, but are compared by value.

Tip Because of the way the ASCII and ANSI character sets are constructed, "Zoo" compares as less than "aardvark." That is, capital letters precede lowercase ones in sequence order.

Passing Parameters to Functions

When you pass a parameter to a function by value, you are making a separate copy of that parameter, a copy that exists only inside the function. If, on the other hand, you pass a parameter by reference, and the function changes the value of that parameter, it is changed everywhere in the script.

Testing Data
When you perform a test by value, you compare two distinct items to see whether they are equal to each other. Usually, this comparison is performed on a byte-by-byte basis. When you test by reference, you are checking to see whether two items are pointers to a single original item. If they are, then they compare as equal; if not, even if they contain the exact same values, byte-for-byte, they compare as unequal.

Copying and passing strings by reference saves memory; but because you cannot change strings once they are created, it becomes possible to compare them by value. This lets you test whether two strings have the same content even if one was generated entirely separately from the other.


Displaying Information in the Browser

Microsoft® JScript™
Displaying Information In the Browser
JScript Tutorial
Previous
Next

Microsoft JScript provides two ways to display data directly in your browser. You can use the write( ) and writeln( ), which are methods of the document object. You can also display information in forms within the browser, and in alert, prompt, and confirm message boxes.

Using document.write( ) and document.writeln( )
The most common way to display information is the write( ) method of the document object. It takes one argument, a string, which it displays in the browser. The string can be either plain text or HTML.

Strings can be enclosed in either single or double quotation marks. This lets you quote something that contains quote marks or apostrophes.

document.write("Pi is approximately equal to " + Math.PI);
document.write( );

Tip The following simple function is a way around having to type "document.write" every time you want something to appear in the browser window. This function does not inform you if something that you attempt to write is undefined, but does let you issue the command "w();", which displays a blank line.

function w(m)  {		// Write function.
m = "" + m + "";        //  Make sure that the m variable is a string.
if ("undefined" != m)  {        //  Test for empty write or other undefined item.
    document.write(m);
    }
document.write("<br>");
}

w('<IMG SRC="horse.gif">');
w();
w("This is an engraving of a horse.");
w();
The writeln( ) method is almost identical to the write( ) method, except that it appends a newline character to whatever string you provide. In HTML this ordinarily results only in a space after your item; but if you're using <PRE> and <XMP> tags, the newline character is interpreted literally and the browser displays it.

When you call the write( ) method, it opens and clears the document if the document is not in the process of being opened and parsed when the write( ) method is called, so it can be dangerous. The example shows a script that is intended to display the time once a minute, but fails to do so after the first time because it clears itself in the process.

<HTML>
<HEAD>
<SCRIPT LANGUAGE="JScript">
function singOut()  {
var theMoment = new Date();
var theHour = theMoment.getHours();
var theMinute = theMoment.getMinutes();
var theDisplacement = (theMoment.getTimezoneOffset() / 60);
theHour -= theDisplacement;
if (theHour > 23)  {
theHour -= 24
}
document.write(theHour + " hours, " + theMinute + " minutes, Coordinated Universal Time.");
window.setTimeout("singOut();", 60000);
}
</SCRIPT>
</HEAD>
<BODY>
<SCRIPT>
singOut();
</SCRIPT>
</BODY>
</HTML>
If you use the alert() method of the window object instead of document.write(), the script works.

window.alert(theHour + " hours, " + theMinute + " minutes, Coordinated Universal Time.");
window.setTimeout("singOut();", 60000);
}
Clearing the Current Document
The clear() method of the document object empties the current document. This method also clears your script (along with the rest of the document), so be very careful how and when you use it.

document.clear();


Microsoft® JScript Language Reference

Microsoft® JScript™
JScript Language Reference 		JScript Tutorial
Version Information

Feature
Information
Alphabetic
Keyword List
Functions
Methods
Objects
Operators
Properties
Statements


JScript Tutorial

Microsoft® JScript™
JScript Tutorial
JScript Language Reference

What Is JScript?
JScript Basics
Writing JScript Code
JScript Variables
JScript Data Types
JScript Operators
Controlling Program Flow
JScript Functions
JScript Objects
JScript Reserved Keywords
Advanced JScript
Using JScript In Internet Explorer


Contents
Feature Information *
  • Data Type Conversion
  • JScript Error Messages
  • JScript Features - ECMA
  • JScript Features - Non-ECMA
  • Microsoft Scripting Run-time Object Features
Keyword List *
  • $1...$9 Properties
  • abs Method
  • acos Method
  • ActiveXObject Object
  • Add Method
  • AddFolders Method
  • Addition Operator (+)
  • anchor Method
  • arguments Property
  • Array Object
  • asin Method
  • Assignment Operator (=)
  • atan Method
  • atan2 Method
  • atEnd Method
  • AtEndOfLine Property
  • AtEndOfStream Property
  • Attributes Property
  • AvailableSpace Property
  • big Method
  • Bitwise AND Operator (&)
  • Bitwise Left Shift Operator (<<)
  • Bitwise NOT Operator (~)
  • Bitwise OR Operator (|)
  • Bitwise Right Shift Operator (>>)
  • Bitwise XOR Operator (^)
  • blink Method
  • bold Method
  • Boolean Object
  • break Statement
  • BuildPath Method
  • caller Property
  • @cc_on Statement
  • ceil Method
  • charAt Method
  • charCodeAt Method
  • Close Method
  • Column Property
  • Comma Operator (,)
  • // (Single-line Comment Statement)
  • /*..*/ (Multiline Comment Statement)
  • CompareMode Property
  • Comparison Operators
  • compile Method
  • Compound Assignment Operators
  • concat Method (Array)
  • concat Method (String)
  • Conditional Compilation
  • Conditional Compilation Variables
  • Conditional (trinary) Operator (?:)
  • constructor Property
  • continue Statement
  • Copy Method
  • CopyFile Method
  • CopyFolder Method
  • cos Method
  • Count Property
  • CreateFolder Method
  • CreateTextFile Method
  • Data Type Conversion
  • Date Object
  • DateCreated Property
  • DateLastAccessed Property
  • DateLastModified Property
  • Decrement Operator (--)
  • Delete Method
  • delete Operator
  • DeleteFile Method
  • DeleteFolder Method
  • Dictionary Object
  • dimensions Method
  • Division Operator (/)
  • do...while Statement
  • Drive Object
  • Drive Property
  • DriveExists Method
  • DriveLetter Property
  • Drives Collection
  • Drives Property
  • DriveType Property
  • E Property
  • Enumerator Object
  • Equality Operator (==)
  • escape Method
  • eval Method
  • exec Method
  • Exists Method
  • exp Method
  • File Object
  • FileExists Method
  • Files Collection
  • Files Property
  • FileSystem Property
  • FileSystemObject Object
  • fixed Method
  • floor Method
  • Folder Object
  • FolderExists Method
  • Folders Collection
  • fontcolor Method
  • fontsize Method
  • for Statement
  • for...in Statement
  • FreeSpace Property
  • fromCharCode Method
  • Function Object
  • function Statement
  • GetAbsolutePathName Method
  • GetBaseName Method
  • getDate Method
  • getDay Method
  • GetDrive Method
  • GetDriveName Method
  • GetExtensionName Method
  • GetFile Method
  • GetFileName Method
  • GetFolder Method
  • getFullYear Method
  • getHours Method
  • getItem Method
  • getMilliseconds Method
  • getMinutes Method
  • getMonth Method
  • GetObject Function
  • GetParentFolderName Method
  • getSeconds Method
  • GetSpecialFolder Method
  • GetTempName Method
  • getTime Method
  • getTimezoneOffset Method
  • getUTCDate Method
  • getUTCDay Method
  • getUTCFullYear Method
  • getUTCHours Method
  • getUTCMilliseconds Method
  • getUTCMinutes Method
  • getUTCMonth Method
  • getUTCSeconds Method
  • getVarDate Method
  • getYear Method
  • Global Object
  • global Property
  • Greater than Operator (>)
  • Greater than or equal to Operator (>=)
  • Identity Operator (===)
  • @if Statement
  • if...else Statement
  • ignoreCase Property
  • Increment Operator (++)
  • index Property
  • indexOf Method
  • Inequality Operator (!=)
  • Infinity Property
  • input Property
  • isFinite Method
  • isNaN Method
  • IsReady Property
  • IsRootFolder Property
  • italics Method
  • item Method
  • Item Property
  • Items Method
  • join Method
  • Key Property
  • Keys Method
  • Labeled Statement
  • lastIndex Property (RegExp)
  • lastIndex Property (Regular Expression)
  • lastIndexOf Method
  • lastMatch Property
  • lastParen Property
  • lbound Method
  • leftContext Property
  • length Property (Array)
  • length Property (Function)
  • length Property (String)
  • Less than Operator (<)
  • Less than or equal to Operator (<=)
  • Line Property
  • link Method
  • LN2 Property
  • LN10 Property
  • log Method
  • LOG2E Property
  • LOG10E Property
  • Logical AND Operator (&&)
  • Logical NOT Operator (!)
  • Logical OR Operator (||)
  • Math Object
  • max Method
  • MAX_VALUE Property
  • min Method
  • MIN_VALUE Property
  • Modulus Operator (%)
  • Move Method
  • MoveFile Method
  • moveFirst Method
  • MoveFolder Method
  • moveNext Method
  • multiline Property
  • Multiplication Operator (*)
  • Name Property
  • NaN Property (Global)
  • NaN Property (Number)
  • NEGATIVE_INFINITY Property
  • new Operator
  • Nonidentity Operator (!==)
  • Number Object
  • Object Object
  • OpenAsTextStream Method
  • OpenTextFile Method
  • Operator Precedence
  • ParentFolder Property
  • parse Method
  • parseFloat Method
  • parseInt Method
  • Path Property
  • PI Property
  • POSITIVE_INFINITY Property
  • pow Method
  • prototype Property
  • random Method
  • Read Method
  • ReadAll Method
  • ReadLine Method
  • RegExp Object
  • Regular Expression Object
  • Regular Expression Syntax
  • Remove Method
  • RemoveAll Method
  • return Statement
  • reverse Method
  • rightContext Property
  • RootFolder Property
  • round Method
  • ScriptEngine Function
  • ScriptEngineBuildVersion Function
  • ScriptEngineMajorVersion Function
  • ScriptEngineMinorVersion Function
  • SerialNumber Property
  • @set Statement
  • setDate Method
  • setFullYear Method
  • setHours Method
  • setMilliseconds Method
  • setMinutes Method
  • setMonth Method
  • setSeconds Method
  • setTime Method
  • setUTCDate Method
  • setUTCFullYear Method
  • setUTCHours Method
  • setUTCMilliseconds Method
  • setUTCMinutes Method
  • setUTCMonth Method
  • setUTCSeconds Method
  • setYear Method
  • ShareName Property
  • ShortName Property
  • ShortPath Property
  • sin Method
  • Size Property
  • Skip Method
  • SkipLine Method
  • slice Method (Array)
  • slice Method (String)
  • small Method
  • sort Method
  • source Property
  • sqrt Method
  • SQRT1_2 Property
  • SQRT2 Property
  • strike Method
  • String Object
  • sub Method
  • SubFolders Property
  • substr Method
  • substring Method
  • Subtraction Operator (-)
  • sup Method
  • switch Statement
  • tan Method
  • test Method
  • TextStream Object
  • this Statement
  • toArray Method
  • toGMTString Method
  • toLocaleString Method
  • toLowerCase Method
  • toString Method
  • TotalSize Property
  • toUpperCase Method
  • toUTCString Method
  • typeof Operator
  • Type Property
  • ubound Method
  • Unary Negation Operator (-)
  • unescape Method
  • Unsigned Right Shift Operator (>>>)
  • UTC Method
  • valueOf Method
  • var Statement
  • VBArray Object
  • void Operator
  • VolumeName Property
  • while Statement
  • with Statement
  • Write Method
  • WriteBlankLines Method
  • WriteLine Method
Functions *
  • GetObject Function
  • ScriptEngine Function
  • ScriptEngineBuildVersion Function
  • ScriptEngineMajorVersion Function
  • ScriptEngineMinorVersion Function
Methods *
  • abs Method
  • acos Method
  • Add Method
  • AddFolders Method
  • anchor Method
  • asin Method
  • atan Method
  • atan2 Method
  • AtEnd Method
  • big Method
  • blink Method
  • bold Method
  • BuildPath Method
  • ceil Method
  • charAt Method
  • charCodeAt Method
  • Close Method
  • compile Method
  • concat Method (Array)
  • concat Method (String)
  • Copy Method
  • CopyFile Method
  • CopyFolder Method
  • cos Method
  • CreateFolder Method
  • CreateTextFile Method
  • Delete Method
  • DeleteFile Method
  • DeleteFolder Method
  • Dimensions Method
  • DriveExists Method
  • escape Method
  • eval Method
  • exec Method
  • Exists Method
  • exp Method
  • FileExists Method
  • fixed Method
  • floor Method
  • FolderExists Method
  • fontcolor Method
  • fontsize Method
  • fromCharCode Method
  • GetAbsolutePathName Method
  • GetBaseName Method
  • getDate Method
  • getDay Method
  • GetDrive Method
  • GetDriveName Method
  • GetExtensionName Method
  • GetFile Method
  • GetFileName Method
  • GetFolder Method
  • getFullYear Method
  • getHours Method
  • getItem Method
  • getMilliseconds Method
  • getMinutes Method
  • getMonth Method
  • GetParentFolderName Method
  • getSeconds Method
  • GetSpecialFolder Method
  • GetTempName Method
  • getTime Method
  • getTimezoneOffset Method
  • getUTCDate Method
  • getUTCDay Method
  • getUTCFullYear Method
  • getUTCHours Method
  • getUTCMilliseconds Method
  • getUTCMinutes Method
  • getUTCMonth Method
  • getUTCSeconds Method
  • getVarDate Method
  • getYear Method
  • indexOf Method
  • isFinite Method
  • isNaN Method
  • italics Method
  • item Method
  • Items Method
  • join Method
  • Keys Method
  • lastIndexOf Method
  • lbound Method
  • link Method
  • log Method
  • max Method
  • min Method
  • Move Method
  • MoveFile Method
  • moveFirst Method
  • MoveFolder Method
  • moveNext Method
  • OpenAsTextStream Method
  • OpenTextFile Method
  • parse Method
  • parseFloat Method
  • parseInt Method
  • pow Method
  • random Method
  • Read Method
  • ReadAll Method
  • ReadLine Method
  • Remove Method
  • RemoveAll Method
  • reverse Method
  • round Method
  • setDate Method
  • setFullYear Method
  • setHours Method
  • setMilliseconds Method
  • setMinutes Method
  • setMonth Method
  • setSeconds Method
  • setTime Method
  • setUTCDate Method
  • setUTCFullYear Method
  • setUTCHours Method
  • setUTCMilliseconds Method
  • setUTCMinutes Method
  • setUTCMonth Method
  • setUTCSeconds Method
  • setYear Method
  • sin Method
  • Skip Method
  • SkipLine Method
  • slice Method (Array)
  • slice Method (String)
  • small Method
  • sort Method
  • sqrt Method
  • strike Method
  • sub Method
  • substr Method
  • substring Method
  • sup Method
  • tan Method
  • test Method
  • toArray Method
  • toGMTString Method
  • toLocaleString Method
  • toLowerCase Method
  • toString Method
  • toUpperCase Method
  • toUTCString Method
  • ubound Method
  • unescape Method
  • UTC Method
  • valueOf Method
  • Write Method
  • WriteBlankLines Method
  • WriteLine Method
Objects *
  • ActiveXObject Object
  • Array Object
  • Boolean Object
  • Date Object
  • Dictionary Object
  • Drive Object
  • Drives Collection
  • Enumerator Object
  • File Object
  • Files Collection
  • FileSystemObject Object
  • Folder Object
  • Folders Collection
  • Global Object
  • Function Object
  • Math Object
  • Number Object
  • Object Object
  • RegExp Object
  • Regular Expression Object
  • String Object
  • TextStream Object
  • VBArray Object
Operators *
  • Addition Operator (+)
  • Assignment Operator (=)
  • Bitwise AND Operator (&)
  • Bitwise Left Shift Operator (<<)
  • Bitwise NOT Operator (~)
  • Bitwise OR Operator (|)
  • Bitwise Right Shift Operator (>>)
  • Bitwise XOR Operator (^)
  • Comma Operator (,)
  • Comparison Operators
  • Compound Assignment Operators
  • Conditional (trinary) Operator (?:)
  • delete Operator
  • Decrement Operator (--)
  • Division Operator (/)
  • Equality Operator (==)
  • Greater than Operator (>)
  • Greater than or equal to Operator (>=)
  • Identity Operator (===)
  • Increment Operator (++)
  • Inequality Operator (!=)
  • Less than Operator(<)
  • Less than or equal to Operator (<=)
  • Logical AND Operator (&&)
  • Logical NOT Operator (!)
  • Logical OR Operator (||)
  • Modulus Operator (%)
  • Multiplication Operator (*)
  • new Operator
  • Nonidentity (!==)
  • Subtraction Operator (-)
  • typeof Operator
  • Unary Negation Operator (-)
  • Unsigned Right Shift Operator (>>>)
  • void Operator
Properties *
  • $1...$9 Properties
  • arguments Property
  • AtEndOfLine Property
  • AtEndOfStream Property
  • Attributes Property
  • AvailableSpace Property
  • caller Property
  • Column Property
  • CompareMode Property
  • Conditional Compilation Variables
  • constructor Property
  • Count Property
  • DateCreated Property
  • DateLastAccessed Property
  • DateLastModified Property
  • Drive Property
  • DriveLetter Property
  • Drives Property
  • DriveType Property
  • E Property
  • Files Property
  • FileSystem Property
  • FreeSpace Property
  • global Property
  • ignoreCase Property
  • index Property
  • Infinity Property
  • input Property
  • IsReady Property
  • IsRootFolder Property
  • Item Property
  • Key Property
  • lastIndex Property (RegExp)
  • lastIndex Property (Regular Expression)
  • lastMatch Property
  • lastParen Property
  • leftContext Property
  • length Property (Array)
  • length Property (Function)
  • length Property (String)
  • Line Property
  • LN2 Property
  • LN10 Property
  • LOG2E Property
  • LOG10E Property
  • MAX_VALUE Property
  • MIN_VALUE Property
  • multiline Property
  • Name Property
  • NaN Property (Global)
  • NaN Property (Number)
  • NEGATIVE_INFINITY Property
  • ParentFolder Property
  • Path Property
  • PI Property
  • POSITIVE_INFINITY Property
  • prototype Property
  • rightContext Property
  • RootFolder Property
  • SerialNumber Property
  • ShareName Property
  • ShortName Property
  • ShortPath Property
  • Size Property
  • source Property
  • SQRT1_2 Property
  • SQRT2 Property
  • SubFolders Property
  • TotalSize Property
  • Type Property
  • VolumeName Property
Statements *
  • break Statement
  • @cc_on Statement
  • Comment Statements
  • continue Statement
  • do...while Statement
  • for Statement
  • for...in Statement
  • function Statement
  • @if Statement
  • if...else Statement
  • Labeled Statement
  • return Statement
  • @set Statement
  • switch Statement
  • this Statement
  • var Statement
  • with Statement
  • while Statement