Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. /*
  2. * VARIABLES:
  3. *
  4. * 0. To hold things in memory during the life-cycle of a program, we can use variables. Variables
  5. * are named identifiers that can point to values of a particular type, like a Number, String,
  6. * Boolean, Array, Object or another data-type. Variables are called so because once created, we
  7. * can CHANGE the value (and type of value) to which they point.
  8. *
  9. * 1. To create a variable we use the keyword, var, followed by a name (id or alias) for our
  10. * variable.
  11. *
  12. * 2. There are 2 phases of using variables: declaration and initialization (or assignment).
  13. */
  14.  
  15. // 1. declaration //
  16. var myName;
  17.  
  18. /*
  19. * At the declaration phase, the variable myName is undefined because we have NOT initialized
  20. * it to anything
  21. */
  22. console.log(myName); // prints => undefined
  23.  
  24. // 2. initialization or assignment //
  25. myName = 'john';
  26. console.log(myName); // prints => john
  27.  
  28. // 3. re-assignment //
  29. myName = 'bob';
  30. console.log(myName); // prints => bob
  31.  
  32. // NOTE: We can assign and re-assign anything to a variable - we cannot do this with constants //
  33. var myVariable = 1;
  34. var myVariable = true;
  35. myVariable = "someString";
  36. </script>
  37.  
  38.  
  39.  
  40. <script id="jsbin-source-javascript" type="text/javascript">/*
  41. * VARIABLES:
  42. *
  43. * 0. To hold things in memory during the life-cycle of a program, we can use variables. Variables
  44. * are named identifiers that can point to values of a particular type, like a Number, String,
  45. * Boolean, Array, Object or another data-type. Variables are called so because once created, we
  46. * can CHANGE the value (and type of value) to which they point.
  47. *
  48. * 1. To create a variable we use the keyword, var, followed by a name (id or alias) for our
  49. * variable.
  50. *
  51. * 2. There are 2 phases of using variables: declaration and initialization (or assignment).
  52. */
  53.  
  54. // 1. declaration //
  55. var myName;
  56.  
  57. /*
  58. * At the declaration phase, the variable myName is undefined because we have NOT initialized
  59. * it to anything
  60. */
  61. console.log(myName); // prints => undefined
  62.  
  63. // 2. initialization or assignment //
  64. myName = 'john';
  65. console.log(myName); // prints => john
  66.  
  67. // 3. re-assignment //
  68. myName = 'bob';
  69. console.log(myName); // prints => bob
  70.  
  71. // NOTE: We can assign and re-assign anything to a variable - we cannot do this with constants //
  72. var myVariable = 1;
  73. var myVariable = true;
  74. myVariable = "someString";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement