1var a = "a";
2var b = "b";
3if (a < b) { // true
4 console.log(a + " est inférieure à " + b);
5} else if (a > b) {
6 console.log(a + " est supérieure à " + b);
7} else {
8 console.log(a + " et " + b + " sont égales.");
9}
1JS String Methods:
2charAt()
3Returns a character at a specified position inside a string
4charCodeAt()
5Gives you the unicode of character at that position
6concat()
7Concatenates (joins) two or more strings into one
8fromCharCode()
9Returns a string created from the specified sequence of UTF-16 code units
10indexOf()
11Provides the position of the first occurrence of a specified text within a string
12lastIndexOf()
13Same as indexOf() but with the last occurrence, searching backwards
14match()
15Retrieves the matches of a string against a search pattern
16replace()
17Find and replace specific text in a string
18search()
19Executes a search for a matching text and returns its position
20slice()
21Extracts a section of a string and returns it as a new string
22split()
23Splits a string object into an array of strings at a specified position
24substr()
25Similar to slice() but extracts a substring depended on a specified number of characters
26substring()
27Also similar to slice() but can’t accept negative indices
28toLowerCase()
29Convert strings to lowercase
30toUpperCase()
31Convert strings to uppercase
32valueOf()
33Returns the primitive value (that has no properties or methods) of a string object
1var abc = "abcdefghijklmnopqrstuvwxyz";
2var esc = 'I don\'t \n know'; // \n new line
3var len = abc.length; // string length
4abc.indexOf("lmno"); // find substring, -1 if doesn't contain
5abc.lastIndexOf("lmno"); // last occurance
6abc.slice(3, 6); // cuts out "def", negative values count from behind
7abc.replace("abc","123"); // find and replace, takes regular expressions
8abc.toUpperCase(); // convert to upper case
9abc.toLowerCase(); // convert to lower case
10abc.concat(" ", str2); // abc + " " + str2
11abc.charAt(2); // character at index: "c"
12abc[2]; // unsafe, abc[2] = "C" doesn't work
13abc.charCodeAt(2); // character code at index: "c" -> 99
14abc.split(","); // splitting a string on commas gives an array
15abc.split(""); // splitting on characters
16128.toString(16); // number to hex(16), octal (8) or binary (2)
17
1const string1 = "A string primitive";
2const string2 = 'Also a string primitive';
3const string3 = `Yet another string primitive`;
4const string4 = new String("A String object");