You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// A string is a sequence of characters enclosed in single quotes (') or double quotes ("). Strings are immutable, meaning that once created, they cannot be changed. However, string methods can be used to manipulate and extract information from strings.
4
+
5
+
// String are Used To Store And Manipulate Text
6
+
7
+
// String -> Collection Of Characters
8
+
9
+
// Single Quotes -> let name = 'dp';
10
+
// Double Quotes -> let name = "dp";
11
+
12
+
letname="dp";
13
+
// console.log(name[3]); -> undefined
14
+
15
+
16
+
// Template Literals
17
+
18
+
// After ES6 -> Template Literals Came In Use -> Use Back Tic
19
+
20
+
letboy1="hmm"
21
+
letboy2='ok'
22
+
23
+
// Print Hmm nice ok
24
+
// let sentence = `boy1 "nice" 'is' boy2` -> We a Make String -> Use Single Or Double Quotes Both Usage Possible If String Made Through Back Tic
25
+
26
+
// String Interpolation
27
+
letsentence=`${boy1} nice ${boy2}`
28
+
console.log(sentence)
29
+
// hmm nice ok
30
+
31
+
letfruit=`Bana\'na`->Bana'na
32
+
console.log(fruit)
33
+
34
+
// \' -> Escape Character -> Count As One Character
35
+
// \n -> New Line
36
+
// \t -> Tab
37
+
// \r -> Carrige Return
38
+
39
+
40
+
// String Method & Properties
41
+
// Accessing Characters:
42
+
// Individual characters in a string can be accessed using square brackets and their index. Remember, indexing starts at 0.
43
+
44
+
// const message = 'Hello';
45
+
// console.log(message[0]); // Output: H
46
+
// console.log(message[3]); // Output: l
47
+
48
+
// String Concatenation:
49
+
// Strings can be concatenated using the + operator or the concat() method.
50
+
51
+
52
+
// const firstName = 'John';
53
+
// const lastName = 'Doe';
54
+
// const fullName = firstName + ' ' + lastName;
55
+
// console.log(fullName); // Output: John Doe
56
+
57
+
// // Using concat()
58
+
// const message = 'Hello, ';
59
+
// const name = 'John';
60
+
// const greeting = message.concat(name);
61
+
// console.log(greeting); // Output: Hello, John
62
+
63
+
// Finding Substrings:
64
+
// The indexOf() method returns the index of the first occurrence of a substring within a string. It returns -1 if the substring is not found.
// The replaceAll() method replaces all occurrences of a specified substring with another substring. It returns a new string. (Available from ECMAScript 2021)
138
+
139
+
140
+
// const message = 'Hello, John! John is a good guy.';
141
+
// console.log(message.replaceAll('John', 'Alice')); // Output: Hello, Alice! Alice is a good guy.
142
+
143
+
// String toUpperCase and toLowerCase:
144
+
// The toUpperCase() and toLowerCase() methods convert a string to uppercase and lowercase, respectively. They return a new string.
// The trimStart() and trimEnd() methods remove whitespace from the beginning and end of a string, respectively. They return a new string. (Available from ECMAScript 2021)
// The padStart() and padEnd() methods pad a string with a specified character to a given length. They return a new string. (Available from ECMAScript 2017)
0 commit comments