Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * STRING MANIPULATION
- *
- * 0. We learned with strings that they go between quotes but there are also ways to manipulate strings
- * like accessing the characters within it or comparing/finding its length.
- *
- * 1. Some of the most usefull ways to operate on a string is checking its length, to build and
- * concatenate them using the + and += string operators, checking for the existence or location
- * of substrings with the indexof() method, or extracting substrings with the substring() method.
- *
- */
- // Character Access //
- // (anyString.charAt(0)); // accesses the first character in that string //
- console.log(('Maria'.charAt(0)));
- //this works as well //
- var name = 'Maria';
- console.log(name[0]);
- // We can do this to find out of the length //
- var firstName = 'Maria';
- console.log(firstName.length);
- // Comparing Strings //
- var a = 'a';
- var b = 'b';
- if (a < b) { // true
- console.log(a + ' is less than ' + b);
- } else if (a > b) {
- console.log(a + ' is greater than ' + b);
- } else {
- console.log(a + ' and ' + b + ' are equal.');
- }
- // Combining strings or "Concatenating" //
- var myVariable1 = 'Maria + ';
- var myVariable2 = 'Emily';
- console.log(myVariable1.concat(myVariable2));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement