Home | Javascript validator | JavaScript Editor JavaScript EditorGet Advanced
JavaScript and Ajax Editor,
Validator and Debugger!

1st JavaScript Editor.

Microsoft® JScript®
instanceof Operator
 Language Reference 
Version 5 

See Also


Description
Returns a Boolean value that indicates whethor or not an object is an instance of a particular class.
Syntax
result = object instanceof class

The instanceof operator syntax has these parts:

Part Description
result Any variable.
object Any object expression.
class Any defined object class.

Remarks
The instanceof operator returns true if object is an instance of class. It returns false if object is not an instance of the specified class, or if object is null.

The following example illustrates the use of the instanceof operator:

function objTest(obj)
{
  var i, t, s = "";            // Create variables.
  t = new Array();             // Create an array.
  t["Date"] = Date;            // Populate the array.
  t["Object"] = Object;
  t["Array"] = Array;
    for (i in t)
    {
      if (obj instanceof t[i]) // Check class of obj.
      {
        s += "obj is an instance of " + i + "\n";
      }
      else 
      {
        s += "obj is not an instance of " + i + "\n";
      }
  }
  return(s);                   // Return string.
}  

var obj = new Date();
response.write(objTest(obj));

Home | Javascript validator | JavaScript Editor JavaScript EditorGet Advanced
JavaScript and Ajax Editor,
Validator and Debugger!

1st JavaScript Editor.