Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. /*Variables-our friends in the age of repetition
  2. Variables are placeholders which allow programs to easily recall
  3. information or actions, alter them, and implement complex operations
  4. in a clear concise manner. They can be thought of as containers for
  5. holding values of any data type including numbers, strings, booleans,
  6. and even functions or objects.
  7. */
  8.  
  9. /*declaring a variable called num1 with "var" keyword
  10. this simply creates a place in memory which can then be assigned to
  11. hold a value in the future. Variables declared in the "global scope" or
  12. outside of a function are stored in the global "window" object and
  13. useable throughout the program.
  14. */
  15. "use strict";
  16.  
  17. var num1;
  18. console.log(num1);//will log "undefined"
  19.  
  20. /*variables that have not yet been assigned a value are set to
  21. undefined by javascript, it is bad practice to set a value to
  22. undefined yourself although completely possible as it makes
  23. debugging and searching out errors more difficult
  24. */
  25.  
  26. //assigning a value to the variable "num1" using the "=" assignment
  27. //operator.
  28.  
  29. num1 = 10;
  30. console.log(num1);//will log 10
  31.  
  32. num1 += 10;
  33. console.log(num1);//will log 20 after altering the numeric value
  34.  
  35. //changing the value of a variable
  36. num1 = "ten";
  37. console.log(num1);//here the value is completely changed to a string
  38. // this will log "ten"
  39.  
  40. //variables can be changed from numbers to strings or other data
  41. // types quickly and easily, and their assigned values will called up
  42. // in the context of their scope.
  43.  
  44. /*
  45. In addition to using variables as containers, we can also call utilize
  46. "constants" and "lets" to hold values, these too can accept any data type
  47. but they behave a bit differently than variables.
  48. */
  49.  
  50. //testing testing
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement