Advertisement
Guest User

Untitled

a guest
Apr 30th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.39 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta name="description" content="Different types of Data">
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width">
  7. <title>Datatypes (Simple and Complex)</title>
  8. </head>
  9. <body>
  10.  
  11. <script id="jsbin-javascript">
  12. /*
  13. * Datatypes:
  14. *
  15. * 0. A data type is a classification identifying types of data such as string, boolean or numbers. It determines the possible values for that particular type.
  16. * To be able to operate on variables, it is important to know something about the type.
  17. * They are categorized into two categories, Simple/Primitive and Comples. There are six primitives
  18. * There are six simple (primitives) datatypes: strings, numbers, Boolean, null, undefined, and NaN.
  19. * Primitive datatypes can only hold single value. Complex datatypes are objects, arrays, and function.
  20. */
  21.  
  22. //1. Numbers //
  23. var a =123;
  24. console.log(a); // prints 123
  25. var a =12.3;
  26. console.log(a); // prints 12.3
  27. //Number types are numerical values that can be both integer and floating point numbers. They can also be positive or negative.//
  28.  
  29. //2.String //
  30. var a = "Superman";
  31. console.log(a); // prints Superman//
  32. var a = 'Hip Hop Hooray';
  33. console.log(a); // prints Hip Hop Hooray//
  34. var b ="Superman returns";
  35. console.log(b); // prints Superman returns//
  36. /*String datatypes is a series of characters written in double or single quotes. Strings are used
  37. *for storing and manipulating text. Strings are immutable.
  38. */
  39.  
  40. //3.Boolean //
  41. console.log(1 > 2); // returns false
  42. var color = "blue";
  43. console.log(color === "blue"); // returns true
  44.  
  45. //Booleans has only two values: true or false.
  46.  
  47. //4.Array //
  48. var color = ["red", "blue", "orange"];
  49. console.log(color); // prints the array//
  50. // Arrays are used to store multiples values in a variable. You create an array with [].
  51. console.log(color[1]); // prints blue
  52. //Arrays elements are numbered, starting with 0.
  53. color.push('black'); // Adds 'black' to the array.
  54. console.log(color);
  55. console.log(color.length); // prints 4//
  56. // Use length to find the total number of elements.//
  57.  
  58. //5.Object //
  59. var man = {
  60. firstName: 'Long',
  61. lastName: 'Nguyen',
  62. age: 2,
  63. };
  64. /* Objects are key value pairs. Access object properties with objectName["propertyName"] or
  65. * objectName.property.Name. */
  66. console.log(man.age); // prints 2//
  67.  
  68. //6.Functions //
  69. /* Functions are a block of code that performs a particular task. It allows the code to
  70. *be ran multiple times with different arguments to produce different results.
  71. *It is defined by function() {} */
  72. function sum(a, b) {
  73. return a + b; // code to be executed. //
  74. };
  75. console.log(sum(1, 1));// prints 2 //
  76.  
  77. //7.Undefined //
  78. // When a variable is declared but the value is not assigned it is undefined.//
  79. var x; // unassigned variable //
  80. console.log(x); // returns undefined //
  81.  
  82. //8. null //
  83. /* Has no value or is empty. Difference between undefined and null is that null
  84. * intentionally has no value. */
  85. var empty = null;
  86. // console.log(empty);// returns nothing//
  87.  
  88. //9. NaN //
  89. /* Not a Number. Nan is the result of doing impossible math with other datatypes.
  90.  
  91. //10.Infinity and -Infinity //
  92. /*Numeric value representing infinity. Value that is greater than any other number.
  93. *Also a producting of diving by 0. */
  94. var beyond = 1/ 0 ; // returns Infinity //
  95. console.log(beyond);
  96. </script>
  97.  
  98.  
  99.  
  100. <script id="jsbin-source-javascript" type="text/javascript">/*
  101. * Datatypes:
  102. *
  103. * 0. A data type is a classification identifying types of data such as string, boolean or numbers. It determines the possible values for that particular type.
  104. * To be able to operate on variables, it is important to know something about the type.
  105. * They are categorized into two categories, Simple/Primitive and Comples. There are six primitives
  106. * There are six simple (primitives) datatypes: strings, numbers, Boolean, null, undefined, and NaN.
  107. * Primitive datatypes can only hold single value. Complex datatypes are objects, arrays, and function.
  108. */
  109.  
  110. //1. Numbers //
  111. var a =123;
  112. console.log(a); // prints 123
  113. var a =12.3;
  114. console.log(a); // prints 12.3
  115. //Number types are numerical values that can be both integer and floating point numbers. They can also be positive or negative.//
  116.  
  117. //2.String //
  118. var a = "Superman";
  119. console.log(a); // prints Superman//
  120. var a = 'Hip Hop Hooray';
  121. console.log(a); // prints Hip Hop Hooray//
  122. var b ="Superman returns";
  123. console.log(b); // prints Superman returns//
  124. /*String datatypes is a series of characters written in double or single quotes. Strings are used
  125. *for storing and manipulating text. Strings are immutable.
  126. */
  127.  
  128. //3.Boolean //
  129. console.log(1 > 2); // returns false
  130. var color = "blue";
  131. console.log(color === "blue"); // returns true
  132.  
  133. //Booleans has only two values: true or false.
  134.  
  135. //4.Array //
  136. var color = ["red", "blue", "orange"];
  137. console.log(color); // prints the array//
  138. // Arrays are used to store multiples values in a variable. You create an array with [].
  139. console.log(color[1]); // prints blue
  140. //Arrays elements are numbered, starting with 0.
  141. color.push('black'); // Adds 'black' to the array.
  142. console.log(color);
  143. console.log(color.length); // prints 4//
  144. // Use length to find the total number of elements.//
  145.  
  146. //5.Object //
  147. var man = {
  148. firstName: 'Long',
  149. lastName: 'Nguyen',
  150. age: 2,
  151. };
  152. /* Objects are key value pairs. Access object properties with objectName["propertyName"] or
  153. * objectName.property.Name. */
  154. console.log(man.age); // prints 2//
  155.  
  156. //6.Functions //
  157. /* Functions are a block of code that performs a particular task. It allows the code to
  158. *be ran multiple times with different arguments to produce different results.
  159. *It is defined by function() {} */
  160. function sum(a, b) {
  161. return a + b; // code to be executed. //
  162. };
  163. console.log(sum(1, 1));// prints 2 //
  164.  
  165. //7.Undefined //
  166. // When a variable is declared but the value is not assigned it is undefined.//
  167. var x; // unassigned variable //
  168. console.log(x); // returns undefined //
  169.  
  170. //8. null //
  171. /* Has no value or is empty. Difference between undefined and null is that null
  172. * intentionally has no value. */
  173. var empty = null;
  174. // console.log(empty);// returns nothing//
  175.  
  176. //9. NaN //
  177. /* Not a Number. Nan is the result of doing impossible math with other datatypes.
  178.  
  179. //10.Infinity and -Infinity //
  180. /*Numeric value representing infinity. Value that is greater than any other number.
  181. *Also a producting of diving by 0. */
  182. var beyond = 1/ 0 ; // returns Infinity //
  183. console.log(beyond);
  184. </script></body>
  185. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement