First Review

1,004 views

Published on

Review of JavaScript data types, variables, assignment and operators.

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,004
On SlideShare
0
From Embeds
0
Number of Embeds
169
Actions
Shares
0
Downloads
18
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

First Review

  1. 1. Review
  2. 2. typeof(13)
  3. 3. typeof(13) // "number"
  4. 4. typeof("potent potables")
  5. 5. typeof("potent potables") // "string"
  6. 6. "potent potables"[0]
  7. 7. "potent potables"[0] // "p"
  8. 8. what character is used to escape inside of strings?
  9. 9. what character is used to escape inside of strings? "this "will" work" "here's another good one" 'here's another good one'
  10. 10. what method will give you the number of characters in a string?
  11. 11. what method will give you the number of characters in a string? length "car".length // 3 "football".length // 8 "longer string with more letters".length // 31
  12. 12. what method will give you the index for a given character in a string?
  13. 13. what method will give you the index for a given character in a string? indexOf
  14. 14. 'baseball'.indexOf('base');
  15. 15. 'baseball'.indexOf('base'); // 0
  16. 16. 'baseball'.indexOf('se');
  17. 17. 'baseball'.indexOf('se'); // 2
  18. 18. "fail".toUpperCase();
  19. 19. "fail".toUpperCase(); // "FAIL"
  20. 20. "WIN".toLowerCase();
  21. 21. "WIN".toLowerCase(); // "win"
  22. 22. "foo".indexOf("bar");
  23. 23. "foo".indexOf("bar"); // -1
  24. 24. var vehicle = {'type':'SUV'}; vehicle.type
  25. 25. var vehicle = {'type':'SUV'}; vehicle.type // "SUV"
  26. 26. var vehicle = {}; vehicle.type = 'SUV'; vehicle.make = 'Ford'; vehicle.model = 'Escape'; vehicle.make;
  27. 27. var vehicle = {}; vehicle.type = 'SUV'; vehicle.make = 'Ford'; vehicle.model = 'Escape'; vehicle.make; // "Ford"
  28. 28. var vehicle = {type: 'SUV', make: 'Ford'}; vehicle['make'];
  29. 29. var vehicle = {type: 'SUV', make: 'Ford'}; vehicle['make']; // "Ford"
  30. 30. var colors = []; colors.length;
  31. 31. var colors = []; colors.length; // 0
  32. 32. var letters = ['z', 'y', 'x', 'w']; letters[1];
  33. 33. var letters = ['z', 'y', 'x', 'w']; letters[1]; // "y"
  34. 34. var letters = ['z', 'y', 'x', 'w']; letters.length;
  35. 35. var letters = ['z', 'y', 'x', 'w']; letters.length; // 4
  36. 36. var letters = ['z', 'y', 'x', 'w']; letters.indexOf('a');
  37. 37. var letters = ['z', 'y', 'x', 'w']; letters.indexOf('a'); // -1
  38. 38. var letters = ['z', 'y', 'x', 'w']; letters.indexOf('z');
  39. 39. var letters = ['z', 'y', 'x', 'w']; letters.indexOf('z'); // 0
  40. 40. var letters = ['z', 'y', 'x', 'w']; letters.indexOf('x');
  41. 41. var letters = ['z', 'y', 'x', 'w']; letters.indexOf('x'); // 2
  42. 42. var letters = ['z', ['y', 'x'], 'w']; letters[1];
  43. 43. var letters = ['z', ['y', 'x'], 'w']; letters[1]; // ['y', 'x']
  44. 44. var letters = ['z', ['y', 'x'], 'w']; letters[1][0];
  45. 45. var letters = ['z', ['y', 'x'], 'w']; letters[1][0]; // 'y'
  46. 46. var letters = ['z', ['y', 'x'], 'w']; letters[1][0]; // 'y' letters[1][1];
  47. 47. var letters = ['z', ['y', 'x'], 'w']; letters[1][0]; // 'y' letters[1][1]; // 'x'
  48. 48. var letters = ['z', ['y', 'x'], 'w']; letters[1][0]; // 'y' letters[1][1]; // 'x' letters[2];
  49. 49. var letters = ['z', ['y', 'x'], 'w']; letters[1][0]; // 'y' letters[1][1]; // 'x' letters[2]; // 'w'
  50. 50. var a = [1, 2]; var b = [3, 4]; var c = a.concat(b); c
  51. 51. var a = [1, 2]; var b = [3, 4]; var c = a.concat(b); c // [1, 2, 3, 4]
  52. 52. ['a', 's', 'd', 'f'].join('');
  53. 53. ['a', 's', 'd', 'f'].join(''); // "asdf"
  54. 54. ['a', 's'].join('/');
  55. 55. ['a', 's'].join('/'); // "a/s"
  56. 56. [1, 2, 3].reverse();
  57. 57. [1, 2, 3].reverse(); // [3, 2, 1]
  58. 58. var last = [1, 2, 3].pop(); last;
  59. 59. var last = [1, 2, 3].pop(); last; // 3
  60. 60. var numbers = [1, 2, 3]; numbers.unshift(4) numbers;
  61. 61. var numbers = [1, 2, 3]; numbers.unshift(4) numbers; // [4, 1, 2, 3]
  62. 62. how do you declare a variable?
  63. 63. how do you declare a variable? var
  64. 64. good or bad? var field;
  65. 65. good or bad? var field;
  66. 66. good or bad? var 2fields;
  67. 67. good or bad? var 2fields; can’t start with numbers
  68. 68. good or bad? var sectionfieldname;
  69. 69. good or bad? var sectionfieldname; no _ between words
  70. 70. good or bad? var section_title;
  71. 71. good or bad? var section_title;
  72. 72. var a = 5; var b = 2; var sum = a + b; sum;
  73. 73. var a = 5; var b = 2; var sum = a + b; sum; // 7
  74. 74. var grade = 4.0; // for answering questions grade -= 0.5; grade;
  75. 75. var grade = 4.0; // for answering questions grade -= 0.5; grade; // 3.5
  76. 76. var remainder = 10 % 2; remainder += 5; remainder;
  77. 77. var remainder = 10 % 2; remainder += 5; remainder; // 5
  78. 78. var current_salary = 40000; var new_salary = 50000; var raise = new_salary > current_salary; raise;
  79. 79. var current_salary = 40000; var new_salary = 50000; var raise = new_salary > current_salary; raise; // true
  80. 80. var current_salary = 50000; var new_salary = current_salary - 10000; var raise = new_salary > current_salary raise;
  81. 81. var current_salary = 50000; var new_salary = current_salary - 10000; var raise = new_salary > current_salary raise; // false
  82. 82. var colors = ['blue', 'red', 'green']; var favorite = 'blue'; colors.indexOf(favorite);
  83. 83. var colors = ['blue', 'red', 'green']; var favorite = 'blue'; colors.indexOf(favorite); // 0
  84. 84. var score = 35; score += 7; score >= 20;
  85. 85. var score = 35; score += 7; score >= 20; // true

×