contents   index   previous   next

in operator


The in operator determines if a property exists in an object. The following script fragment illustrates for the discussion in this section:


var isProp;

var obj = {one:111, two:222, Three:333};

var test = 'one';


isProp = test in obj;


if (isProp)


Screen.writeln('two' in obj);

Screen.writeln('three' in obj);



Display is:






The script above defines an object, obj, with three properties: "one", "two", and "Three" (note the capitalization). The in operator is used three times to see if the following strings are properties in obj: "one", "two", "three" (note the capitalization). The first two uses of in result in true and the third in false. Look at the expression "test in obj". The expression to the left, in this case test, of the in operator must be a string or be able to convert to a string (since properties of objects are represented as strings). The expression to the right must be an object or array.


ScriptEase JavaScript has a global.defined() function which is useful. The in operator may be used in a similar way. In the following fragment, both in and defined() result in true, and the display is:





The fragment is:


var test = 'TEST';


Screen.writeln('test' in global);



instanceof operator