Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.92 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width">
  6. <title>JS Bin</title>
  7. </head>
  8. <body>
  9.  
  10. <script id="jsbin-javascript">
  11. //dataTypes:complex
  12. //Objects, Arrays, and Functions are complex types, and one characteristic of complex types is that they can be of any size.
  13. //complex types are copied by reference.
  14. //stored as reference when assigned to a variable
  15. //Objects can contain any number of key/value pairs.
  16. //Arrays can contain any number of elements, and
  17. //Functions can encapsulate any number of statements.
  18.  
  19. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  20.  
  21. //array:
  22. //collection of value as a list
  23. //arrays are used to store multiple values in a single variable, using the [ ] sign, with a comma(,)between values.
  24. var num1=1;
  25. var num2=2;
  26. var num3=3;
  27. var num4=4;
  28. var num5=5;
  29. var arrayNum=[1,2,3,4,5];
  30.  
  31. var car1="acuro";
  32. var car2="beebee";
  33. var car3="chena";
  34. var car4="toto";
  35. var car5="wolfwolf";
  36. var arrayCar=["acura","beebee","chena","toto","wolfwolf"];
  37. // you can add more element if needed
  38.  
  39. //array are zero indexed, it start its count from 0(zer0)
  40.  
  41. //arrayCar[0] is the first element "acura"
  42. //arrayCar[1] is the second element "beebee"
  43. //arrayCar[2] is the third element "chena"
  44. //arrayCar[3] is the fourth element "toto"
  45. //arrayCar[4] is the fifth element "wolfwolf" or you can use (arrayCar.length-1) to get the last element
  46.  
  47. //you can modify the array
  48. //methods modify the array:
  49.  
  50.  
  51. //.pop() removes the last element from an array
  52. arrayCar.pop(); //=>["acura","beebee","chena","toto"];
  53.  
  54. //.push() method adds a new element to the end of an array
  55. arrayCar.push("yoda"); //=>["acura","beebee","chena","toto","wolfwolf","yoda]
  56.  
  57. //.shift() method removes the first array element and "shifts" all other elements to a lower index.
  58. arrayCar.shift(); //=>["beebee","chena","toto","wolfwolf"]
  59.  
  60. //.unshift() method adds a new element to an array at the beginning, and "unshifts" older elements:
  61. arrayCar.unshift("cat"); //=>["cat","acura","beebee","chena","toto","wolfwolf"]
  62.  
  63. //.toString() converts an array to a string seperated by comma.
  64. arrayCar.toString(); //=>"acura,beebee,chena,toto,wolfwolf"
  65.  
  66. //.join() method also joins all array elements into a string.
  67. //It behaves just like toString(), but in addition you can specify the separator:
  68. arrayCar.join("."); //=>"acura.beebee.chena.toto.wolfwolf"
  69.  
  70. //.sort() method sorts an array alphabetically:
  71. arrayCar.sort(); //=>"acura.beebee.chena.toto.wolfwolf"
  72.  
  73. //.reverse() method reverses the elements in an array.
  74. arrayCar.reverse(); //=>["wolfwolf", "toto", "chena", "beebee", "acura"]
  75.  
  76. //.length property of an array returns the length of an array (the number of array elements).
  77. arrayCar.length(); //=>5
  78.  
  79. //changing the value of an array
  80. arrayCar[0]="poopoo"; //=>["poopoo","beebee","chena","toto","wolfwolf"];
  81.  
  82. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  83.  
  84. //object:
  85. // object literal are created with {}
  86. //In JavaScript, arrays use numbered indexes.
  87. //In JavaScript, objects use named indexes.
  88. // collection of key:value pair seperated by a colon(:)
  89. var objectTest={car:"doodoo",
  90. color:"clear",
  91. speed:5,
  92. rival:["yoda","chekke"]};
  93.  
  94. // You can access object properties in two ways:dot. and bracket [] notation
  95. objectTest.car; //=>"doodoo"
  96. objectTest["car"]; //=> "doodoo"
  97. //but use dot notation. its better for the enviroment.
  98. objectTest.color; //=>"clear"
  99. objectTest.rival; //=>["yoda", "chekke"]
  100. objectTest.rival[0]; //=>"yoda"
  101.  
  102. //You can add new properties to an existing object by simply giving it a value.
  103. objectTest.cost=135;
  104.  
  105. //The delete keyword deletes a property from an object:
  106. delete objectTest.color;
  107.  
  108.  
  109. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  110.  
  111. //function:
  112. //perform action on data and return it
  113. //Functions allow us to encapsulate a block of code, and execute that block of code whenever we want and how ever many times we want when its called.
  114. //Two phases of using Functions:1)declaration/definition: creating the Function.2)invocation/calling/executing/applying: using the Function.
  115.  
  116. function functionNameHere(parameter) { "code to be excuted goes here";}
  117. var functionTest0=100;
  118. function functionTest1(a,b){return a+b;} //=>a+b
  119. function functionTest2(a,b,c){return a+b;} //=>a+b
  120. function functionTest3(a,b,c,d){return a+b+c+d+e+a;} //=>error "ReferenceError: e is not defined
  121. function functionTest4(){return "hello"+functionTest0+"world";} //=>hello100world
  122.  
  123. //Accessing a function without () will return the function definition instead of the function result:
  124. functionTest4; //=>function functionTest(){return "hello"+functionTest0+"world";}
  125. </script>
  126.  
  127.  
  128.  
  129. <script id="jsbin-source-javascript" type="text/javascript">//dataTypes:complex
  130. //Objects, Arrays, and Functions are complex types, and one characteristic of complex types is that they can be of any size.
  131. //complex types are copied by reference.
  132. //stored as reference when assigned to a variable
  133. //Objects can contain any number of key/value pairs.
  134. //Arrays can contain any number of elements, and
  135. //Functions can encapsulate any number of statements.
  136.  
  137. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  138.  
  139. //array:
  140. //collection of value as a list
  141. //arrays are used to store multiple values in a single variable, using the [ ] sign, with a comma(,)between values.
  142. var num1=1;
  143. var num2=2;
  144. var num3=3;
  145. var num4=4;
  146. var num5=5;
  147. var arrayNum=[1,2,3,4,5];
  148.  
  149. var car1="acuro";
  150. var car2="beebee";
  151. var car3="chena";
  152. var car4="toto";
  153. var car5="wolfwolf";
  154. var arrayCar=["acura","beebee","chena","toto","wolfwolf"];
  155. // you can add more element if needed
  156.  
  157. //array are zero indexed, it start its count from 0(zer0)
  158.  
  159. //arrayCar[0] is the first element "acura"
  160. //arrayCar[1] is the second element "beebee"
  161. //arrayCar[2] is the third element "chena"
  162. //arrayCar[3] is the fourth element "toto"
  163. //arrayCar[4] is the fifth element "wolfwolf" or you can use (arrayCar.length-1) to get the last element
  164.  
  165. //you can modify the array
  166. //methods modify the array:
  167.  
  168.  
  169. //.pop() removes the last element from an array
  170. arrayCar.pop(); //=>["acura","beebee","chena","toto"];
  171.  
  172. //.push() method adds a new element to the end of an array
  173. arrayCar.push("yoda"); //=>["acura","beebee","chena","toto","wolfwolf","yoda]
  174.  
  175. //.shift() method removes the first array element and "shifts" all other elements to a lower index.
  176. arrayCar.shift(); //=>["beebee","chena","toto","wolfwolf"]
  177.  
  178. //.unshift() method adds a new element to an array at the beginning, and "unshifts" older elements:
  179. arrayCar.unshift("cat"); //=>["cat","acura","beebee","chena","toto","wolfwolf"]
  180.  
  181. //.toString() converts an array to a string seperated by comma.
  182. arrayCar.toString(); //=>"acura,beebee,chena,toto,wolfwolf"
  183.  
  184. //.join() method also joins all array elements into a string.
  185. //It behaves just like toString(), but in addition you can specify the separator:
  186. arrayCar.join("."); //=>"acura.beebee.chena.toto.wolfwolf"
  187.  
  188. //.sort() method sorts an array alphabetically:
  189. arrayCar.sort(); //=>"acura.beebee.chena.toto.wolfwolf"
  190.  
  191. //.reverse() method reverses the elements in an array.
  192. arrayCar.reverse(); //=>["wolfwolf", "toto", "chena", "beebee", "acura"]
  193.  
  194. //.length property of an array returns the length of an array (the number of array elements).
  195. arrayCar.length(); //=>5
  196.  
  197. //changing the value of an array
  198. arrayCar[0]="poopoo"; //=>["poopoo","beebee","chena","toto","wolfwolf"];
  199.  
  200. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  201.  
  202. //object:
  203. // object literal are created with {}
  204. //In JavaScript, arrays use numbered indexes.
  205. //In JavaScript, objects use named indexes.
  206. // collection of key:value pair seperated by a colon(:)
  207. var objectTest={car:"doodoo",
  208. color:"clear",
  209. speed:5,
  210. rival:["yoda","chekke"]};
  211.  
  212. // You can access object properties in two ways:dot. and bracket [] notation
  213. objectTest.car; //=>"doodoo"
  214. objectTest["car"]; //=> "doodoo"
  215. //but use dot notation. its better for the enviroment.
  216. objectTest.color; //=>"clear"
  217. objectTest.rival; //=>["yoda", "chekke"]
  218. objectTest.rival[0]; //=>"yoda"
  219.  
  220. //You can add new properties to an existing object by simply giving it a value.
  221. objectTest.cost=135;
  222.  
  223. //The delete keyword deletes a property from an object:
  224. delete objectTest.color;
  225.  
  226.  
  227. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  228.  
  229. //function:
  230. //perform action on data and return it
  231. //Functions allow us to encapsulate a block of code, and execute that block of code whenever we want and how ever many times we want when its called.
  232. //Two phases of using Functions:1)declaration/definition: creating the Function.2)invocation/calling/executing/applying: using the Function.
  233.  
  234. function functionNameHere(parameter) { "code to be excuted goes here";}
  235. var functionTest0=100;
  236. function functionTest1(a,b){return a+b;} //=>a+b
  237. function functionTest2(a,b,c){return a+b;} //=>a+b
  238. function functionTest3(a,b,c,d){return a+b+c+d+e+a;} //=>error "ReferenceError: e is not defined
  239. function functionTest4(){return "hello"+functionTest0+"world";} //=>hello100world
  240.  
  241. //Accessing a function without () will return the function definition instead of the function result:
  242. functionTest4; //=>function functionTest(){return "hello"+functionTest0+"world";}
  243.  
  244. </script></body>
  245. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement