Advertisement
Guest User

javascript

a guest
Jun 28th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.80 KB | None | 0 0
  1. how to write a comments in javascript:
  2.  
  3. inline comments:
  4.  
  5. (sample script) //this is an inline comment
  6.  
  7. multi-line comments:
  8.  
  9. /* this is a multi-line comment*/
  10.  
  11. javascript data types:
  12.  
  13. undefined = something that hasn't been defined
  14.  
  15. null = nothing
  16. boolean = true or false
  17. string = any sort of text
  18. symbol = immutable primitive vaule that is unique
  19. number = number
  20. object =
  21.  
  22. How to use variables:
  23.  
  24. The three ways to declare variables:
  25.  
  26. 1 let (for example: let myname = "mateocoltura")
  27. 2 const (for example: const pi = 3.14)
  28. 3 var (for example: var myname = "mateo", var myname= "8" )
  29.  
  30. Difference between var, const, and let:
  31.  
  32. var is able to be used troughout your whole program
  33. let wil only will be used within the scope where you declare it
  34. const is a variable that should/can never change
  35.  
  36. declaring a variable (declaring and assigning in one line) :
  37.  
  38. var b = 2;
  39.  
  40. assigning a variable (letting it be called a for example):
  41.  
  42. var a;
  43.  
  44. now i can give a a value without var before it because it has already been assigned:
  45.  
  46. a = 7;
  47. b = a;
  48.  
  49. this can be used in the console:
  50.  
  51. if var a = 7 when i type: "console.log(a)" it will display 7 in the console
  52.  
  53. uninitalized variables:
  54.  
  55. var a;
  56. var b;
  57. var c;
  58.  
  59. initialzed variables:
  60.  
  61. var a = 5;
  62. var b = 10;
  63. var c = "i am a string" (must always be between quotation marks)
  64.  
  65. calculating with initialized variables:
  66.  
  67. if "var a = 5;" then "a = a + 1;" equals: "6"
  68. if "var b = 10;" then "b = b + 5;" equals: "15"
  69. if "var c = "I am a" then "c = c + "String";" equals: "I am a string!"
  70.  
  71. VARIABLE DECLARATIONS AND ASSIGNMENTS ARE CASE SENSITIVE, if you have multiple things to declare to a var you use studlyCapVar by starting the first word with a lowercase and the next words with Uppercase, for example:
  72.  
  73. johnLucasBob
  74. ericaThomasJade
  75. AppleBottomJeans
  76.  
  77. Adding numbers in javascript:
  78.  
  79. var sum = 10 + 10;
  80.  
  81. Subtracting numbers in javascript:
  82.  
  83. var difference = 20 - 10;
  84.  
  85. Multiplying numbers in javascript:
  86.  
  87. var product = 8 * 1;
  88.  
  89. Dividing numbers in javascript:
  90.  
  91. var quotient = 66 / 2;
  92.  
  93.  
  94. for example: if "var sum = 10 + 10" then "console.log(sum)" will display the number 20 in the console
  95.  
  96. Incrementing numbers:
  97.  
  98. if "var myVar = 87;" then you can increment by doing: "myVar++;"
  99.  
  100. Decrementing numbers:
  101.  
  102. if "var Myvar = 87;" then you can decrement by doing: "Myvar--;"
  103.  
  104. Decimal numbers:
  105.  
  106. var myDecimal = 0.009
  107.  
  108. Multiplying decimal numbers:
  109.  
  110. var product = 2.0 * 2.5;
  111.  
  112. Dividing decimal numbers:
  113.  
  114. var quotient = 4.4 / 2.0;
  115.  
  116. Finding a remainder: (the remainder operator gives the remainder of a division of two numbers)
  117.  
  118. var remainder = 11 % 3; (=2)
  119.  
  120. The remainder operator is often used to determine if a number is even or odd,
  121. if you can divide a number by 2 and the remainder is 0 that means the number is even
  122.  
  123.  
  124. Compound assignment with augmented addition:
  125.  
  126. var a = 3;
  127.  
  128. a = a + 12
  129.  
  130. shortcut:
  131.  
  132. a += 12
  133.  
  134. Compound assignment with augmented substraction:
  135.  
  136. var a = 11;
  137.  
  138. a = a - 6;
  139.  
  140. shortcut:
  141.  
  142. a -= 6;
  143.  
  144. Compound assignemt with augmented multiplication:
  145.  
  146. var a = 5;
  147.  
  148. a = a * 5;
  149.  
  150. shortcut:
  151.  
  152. a *= 5
  153.  
  154. compound assignemt with augmented division:
  155.  
  156. var a = 48;
  157.  
  158. a = a / 12
  159.  
  160. shortcut:
  161.  
  162. a /= 12
  163.  
  164. Declaring string variables:
  165.  
  166. var myFirstName = "Mateo";
  167. var myLastName = "Coltura";
  168.  
  169. Escaping literal quotes in strings:
  170.  
  171. var myStr = "i am a "double quoted" string inside "double quotes"
  172.  
  173. what you should do when you want to use quotes inside a string:
  174.  
  175. var myStr = "I am a \"double quoted\" string inside \"double quotes\" "
  176.  
  177. Quoting strings with single quotes:
  178.  
  179. var myStr = "< a href=\"https://www.example.com\" target= \"_blank\">Link</a>
  180.  
  181. what you should do is use single quotation marks because you can also use them.
  182.  
  183. var myStr = '<a href="https://www.example.com" target="blank">link</a>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement