August 17, 2024
JavaScript Strings
Generally a string is a collection of characters. In JavaScript strings are objects. String objects have several properties and methods through these properties and methods you can perform some operations and tasks as per your requirement. Properties are some basic information about the string object such as length is property of string object which returns you length of a string. Methods are also called functions. Through methods you can perform some tasks with strings such as you can compare two strings, you can search and replace the string and many more which you would be come to know through this JavaScript tutorial. The example of a string and how to access properties and how to use methods of a string mentioned below:
Code
<script type='text/javascript' language='javascript'>
var StringVariable = 'Hello All, this is a string example';
// you can also create string object with below mentioned
// statement.
SecontString = new String('I am a Second String.');
// below mention statement shows you how to access property
// of a string object
var result = StringVariable.property;
// below mention statement shows you how to access method
// of a string object
var FunctionResult = StringVariable.function(parameters);
</script>