STRING METHODS
What are STRINGS?
Strings are for storing text .Strings are written with quotes. A string in JavaScript is a sequence of characters enclosed in either single or double quotes.
JavaScript provides a number of built-in methods for manipulating strings. Some of the most commonly used string methods are:
length
This method returns the number of characters in a string. For example, the following code will return 11:
1var str = "Hello World";
2console.log(str.length);
concat
This method is used to concatenate (combine) two or more strings. For example, the following code will return "Hello World":
1var str1 = "Hello";
2var str2 = " World";
3console.log(str1.concat(str2));
slice
This method is used to extract a portion of a string. For example, the following code will return "World":
replace
This method is used to replace a specific character or substring in a string. For example, the following code will return "Hello Universe":
1var str = "Hello World";
2console.log(str.replace("World", "Universe"));
toUpperCase and toLowerCase
These methods are used to convert a string to uppercase or lowercase letters. For example, the following code will return "HELLO WORLD" and "hello world" respectively:
1var str = "Hello World";
2console.log(str.toUpperCase());
3console.log(str.toLowerCase());
These are just a few of the many string methods available in JavaScript. By understanding the basics of strings and the various methods that can be used to manipulate them, you can create more dynamic and interactive web pages. So, start experimenting with different string methods and see what you can create!