Advertisement
WhiteofNotGrey

Untitled

Jun 8th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* String: Any form of text */
  2. /*Object: Stores a lot of key value pairs*/
  3.  
  4. /* declaring variables */
  5.  
  6. var  myName = "Beau"
  7. /*can be used throughout program*/
  8.  
  9. myName = 8
  10.  
  11. let ourName = "freeCodeCamp"
  12. /* may only be used within scope of where you declare that*/
  13.  
  14. const pi = 3.14
  15. /*can never change*/
  16.  
  17. var a;
  18. /* declaring a variable, called a */
  19.  
  20. var b =2;
  21. /*declaring a, assigning 2*/
  22.  
  23. a = 7;
  24. /* a has already been declared*/
  25.  
  26. b = a;
  27. /* you have assigned contents of a to b*/
  28.  
  29. /*initializing a variable to an inital value at the same time it's declared*/
  30. var a =9;
  31. /* a: declare, 9: initizing*/
  32.  
  33. /* adding/subtracting numbers */
  34. var sum = 10 + 10;
  35. console.log(sum)
  36.  
  37. var difference = 20 - 10;
  38.  
  39. var product = 8 * 10;
  40.  
  41. var quotient = 66/2;
  42.  
  43. /*Incrementing numbers*/
  44. /* refers to adding 1 to it*/
  45.  
  46. var myVar = 81;
  47.  
  48. myVar = myVar + 1;
  49.  
  50. /*or*/
  51.  
  52. myVar++;
  53.  
  54. /*decrementing numbers*/
  55. /* minus 1 to it*/
  56.  
  57. var dcVar = 11;
  58.  
  59. dcVar = dcVar - 1;
  60.  
  61. /*or*/
  62.  
  63. dcVar--;
  64.  
  65. /*decimal numbers*/
  66.  
  67. var myDecimal = 5.7;
  68.  
  69. var secondDecimal = 0.0007;
  70.  
  71. /*Multiplying decimals*/
  72.  
  73. var product = 2.0 * 2.5;
  74. console.log(product)
  75.  
  76. /*Dividing decimals*/
  77.  
  78. var quotient = 6.4/2.0;
  79.  
  80. /*finding the remainder*/
  81. var remainder;
  82. remainder = 11 % 3;
  83.  
  84. 1821
  85.  
  86. ////////
  87. Variables are used to store data temporarily
  88.  
  89. - Data is stored somewhere, and give that memory location a name
  90.  
  91. - With this name, you may read the data and at a given location
  92.  
  93. A variable = box
  94.  
  95. What's inside the box = Value that we assign to variable (data)
  96.  
  97. Strings are a sequence of characters.
  98.  
  99.  
  100.  
  101. Rules of naming variables
  102.  
  103. - Do not use prexisting keywords used already
  104. - Meaningful, should be clear instead of a1, b and c
  105. - cannot start with a number (1name etc)
  106. - cannot contain space or hyphen (-)
  107. - case sensitive
  108.  
  109. To declare multiple variables
  110.  
  111. let firstName = "NumberOne";
  112. let lastName = "NumberTwo";
  113.  
  114.  
  115. value of variables (let) can change, but
  116. the value of a constant cannot.
  117.  
  118.  
  119. If you don't need to reassign, constant should be used.
  120. If you do, use let
  121.  
  122. undefined: if value is not initalized, by default, its value is undefined
  123. null is used to clear value of variable
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement