By string literal: The string literal is created using double quotes.
Example: var stringname="string value";
By string object: It is done using new keyword. We will talk about objects more in later sections.
Example: var stringname=new String("string literal");
String Length: To find the length of a string, we may use length property.
var x = "abcd";
var z = x.length;
Here, 4 will be stored in z.
Note: Suppose we store “I am “Adarsh” Chaudhary” in some variable then only “I am “ will be stored. To avoid this situation we use backslash escape character. It makes special charatcer into string characters. So here we should use “I am "Adarsh" Chaudhary”.
Try the following example in the editor below.
You are given a string S, you have to print the string followed by it’s length.