contents   index   previous   next



Properties and methods of basic data types

 

The basic data types, such as Number and String, have properties and methods assigned to them that may be used with any variable of that type. For example, all String variables may use all String methods.

 

The properties and methods of the basic data types are retrieved in the same way as from objects. For the most part, they are used internally by the interpreter, but you may use them if choose. For example, if you have a numeric variable called number and you want to convert it to a string, you can use the toString() method as illustrated in the following fragment.

 

   var n = 5

   var s = n.toString()

 

After this fragment executes, the variable n contains the number 5 and the variable s contains the string "5".

 

The following two methods are common to all variables and data types.

 


toString()

valueOf()