Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta name="description" content="The In's and Out's of Variables">
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width">
  7. <title>Variables</title>
  8. </head>
  9. <body>
  10.  
  11. <script id="jsbin-javascript">
  12. /*
  13. VARIABLES:
  14. Containers that hold different types of data;
  15. they're named containers that hold things into memory.
  16. 1. They can contain primitive as well as complex data types including:
  17. Strings
  18. Booleans
  19. Numbers
  20. Null
  21. Objects
  22. Arrays
  23. 2. You can change the values that variables hold
  24. 3. There are two phases that variables go through; declaration and assignment.
  25.  
  26. */
  27.  
  28. /* To declare a variable is to give it a name; you do this by first
  29. implementing the keyword var followed by the name and a semicolon.
  30. */
  31.  
  32. // Example:
  33. 'use strict';
  34.  
  35. var myName;
  36. var myAge;
  37.  
  38. /* At the declaration phase variables are automatically set to undefined
  39. because it has yet to be assigned a value. Javascript basically says "Yes, this
  40. variable exists but you haven't put anything in it."
  41.  
  42. */
  43. console.log(myName); // prints out undefined
  44. console.log(myAge); // prints out undefined
  45.  
  46. /* To assign a variable is to give it a value after it has been declared;
  47. you do this by using the = operator and then typing a value to be stored.
  48.  
  49. */
  50.  
  51. //Example:
  52. var myCity = 'New Orleans';
  53. var gender = 'Female';
  54.  
  55. console.log(myCity); //prints out "New Orleans"
  56.  
  57. // We can also reassign values to variables without having to re-declare them.
  58. //Example:
  59.  
  60. myCity = 'Chicago';
  61. console.log(myCity); // prints out "Chicago"
  62. </script>
  63.  
  64.  
  65.  
  66. <script id="jsbin-source-javascript" type="text/javascript">/*
  67. VARIABLES:
  68. Containers that hold different types of data;
  69. they're named containers that hold things into memory.
  70. 1. They can contain primitive as well as complex data types including:
  71. Strings
  72. Booleans
  73. Numbers
  74. Null
  75. Objects
  76. Arrays
  77. 2. You can change the values that variables hold
  78. 3. There are two phases that variables go through; declaration and assignment.
  79.  
  80. */
  81.  
  82. /* To declare a variable is to give it a name; you do this by first
  83. implementing the keyword var followed by the name and a semicolon.
  84. */
  85.  
  86. // Example:
  87. var myName;
  88. var myAge;
  89.  
  90. /* At the declaration phase variables are automatically set to undefined
  91. because it has yet to be assigned a value. Javascript basically says "Yes, this
  92. variable exists but you haven't put anything in it."
  93.  
  94. */
  95. console.log(myName); // prints out undefined
  96. console.log(myAge); // prints out undefined
  97.  
  98. /* To assign a variable is to give it a value after it has been declared;
  99. you do this by using the = operator and then typing a value to be stored.
  100.  
  101. */
  102.  
  103. //Example:
  104. var myCity = 'New Orleans'
  105. var gender = 'Female'
  106.  
  107. console.log(myCity); //prints out "New Orleans"
  108.  
  109. // We can also reassign values to variables without having to re-declare them.
  110. //Example:
  111.  
  112. myCity = 'Chicago';
  113. console.log(myCity); // prints out "Chicago"
  114. </script></body>
  115. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement