Advertisement
Guest User

Untitled

a guest
Aug 28th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. /*
  2. * STRING MANIPULATION
  3. *
  4. * 0. We learned with strings that they go between quotes but there are also ways to manipulate strings
  5. * like accessing the characters within it or comparing/finding its length.
  6. *
  7. * 1. Some of the most usefull ways to operate on a string is checking its length, to build and
  8. * concatenate them using the + and += string operators, checking for the existence or location
  9. * of substrings with the indexof() method, or extracting substrings with the substring() method.
  10. *
  11. */
  12. // Character Access //
  13. // (anyString.charAt(0)); // accesses the first character in that string //
  14. console.log(('Maria'.charAt(0)));
  15. //this works as well //
  16. var name = 'Maria';
  17. console.log(name[0]);
  18.  
  19.  
  20. // We can do this to find out of the length //
  21. var firstName = 'Maria';
  22. console.log(firstName.length);
  23.  
  24. // Comparing Strings //
  25. var a = 'a';
  26. var b = 'b';
  27. if (a < b) { // true
  28. console.log(a + ' is less than ' + b);
  29. } else if (a > b) {
  30. console.log(a + ' is greater than ' + b);
  31. } else {
  32. console.log(a + ' and ' + b + ' are equal.');
  33. }
  34.  
  35. // Combining strings or "Concatenating" //
  36. var myVariable1 = 'Maria + ';
  37. var myVariable2 = 'Emily';
  38. console.log(myVariable1.concat(myVariable2));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement