Guest User

Untitled

a guest
Apr 27th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 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. 'use strict';
  17.  
  18. var myName;
  19.  
  20. /*
  21. * At the declaration phase, the variable myName is undefined because we have NOT initialized
  22. * it to anything
  23. */
  24. console.log(myName); // prints => undefined
  25.  
  26. // 2. initialization or assignment //
  27. myName = 'john';
  28. console.log(myName); // prints => john
  29.  
  30. // 3. re-assignment //
  31. myName = 'bob';
  32. console.log(myName); // prints => bob
  33.  
  34. // NOTE: We can assign and re-assign anything to a variable - we cannot do this with constants //
  35. var myVariable = 1;
  36. var myVariable = true;
  37. myVariable = "someString";
Advertisement
Add Comment
Please, Sign In to add comment