GP_JS_Strings
GP_JS_Strings
Overview
The String object is used to represent and manipulate a sequence of characters.
It could be written with both single and double quotes.
Length
The length of the string could be found using built-in property.
Double quotes :
Backslash :
1
Creating Strings
Strings are primitive data types created from literals.
Strings can also be defined as objects with the keyword new as we did in arrays.
Comparing Strings
Using == operator :
console.log(str1 == str2) ; // true as only the values are checked and not the data type
console.log(str1 === str2) ; // false because of strict equality operator , data types are
also checked
2
String Methods
1. substring( ) : It is used to find a contiguous sequence of characters within a
string using indxes
3
Searching Methods in Strings
1. indexOf( ) : This method returns the index of (the position of) the first
occurrence of a specified character/text in a string