contents   index   previous   next



String as object

 

Strictly speaking, the String object is not truly an object. It is a hybrid of a primitive data type and of an object. As an example of its hybrid nature, when strings are assigned using the assignment operator, the equal sign, the assignment is by value, that is, a copy of a string is actually transferred to a variable. Further, when strings are passed as arguments to the parameters of functions, they are passed by value. Objects, on the other hand, are assigned to variables and passed to parameters by reference, that is, a variable or parameter points to or references the original object.

 

Strings have both properties and methods which are listed in this section. These properties and methods are discussed as if strings were pure objects. Strings have instance properties and methods and are shown with a period, ".", at their beginnings. A specific instance of a variable should be put in front of a period to use a property or call a method. The exception to this usage is a static method which actually uses the identifier String, instead of a variable created as an instance of String. The following code fragment shows how to access the .length property, as an example for calling a String property or method:

 

var TestStr = "123";

var TestLen = TestStr.length;

 

String properties

 


String object instance properties