Of the above objects, the most widely used one is the String object.
Objects are nothing but special kind of data. Each object has Properties and Methods associated with it.
Properties of an Object:
Property is the value that is tagged to the object. For example let us consider one of the properties associated with the most popularly used String object – the length property. Length property of the string object returns the length of the string, that is in other words the number of characters present in the string.
General syntax of using the length property of the string object is as below:
Here variablename is the name of the variable to which the string is assigned and length is the keyword.
The output of the above is
We see that the property of an object is the value associated with the object.
Method of an Object:
Some of the Methods associated with String Object are:
All these methods are used to perform actions on the String object.
If a programmer wants the value of String object in lowercase then the method toLowerCase() is used on String Object
To convert a string to upper case, the method toUpperCase() is used.
If a programmer wants to know the position of a characters or group of characters in a String Object it can be determined by applying indexof method to the String.
Example to understand how method can be used in an Object.
In the example below, we have used toUpperCase method of String object.
The output of the above script is
In the above script since the method toUpperCase is applied to the string object exf which has value initialized as Welcome all letters get converted as upper case and hence the output is as above.