Advertisement
wingman007

FrontEnd_JavaScript_lection2_AlgorithmsDataStructures.js

Apr 25th, 2014
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // "use strict";
  2.  
  3. var number = 5;
  4. var string = "Stoyan";
  5. var strint5 = new String("Stoyan");
  6. var bool = true;
  7. var stoyan = { name: "Stoyan", age: 50};
  8. var primes = [2, 3, 5, 7];
  9. function MyFunction(){};
  10. string  = {};
  11. var myObject2 = {a: 4, b: 5};
  12. var hex = 0xA;
  13. var oct = 010;
  14. var t = 1.4E+10;
  15. // - + * / %
  16. var then = new Date(2014, 11, 1);
  17. var string2 = "dsda \
  18. sdfsdf \
  19. sdsadas";
  20.  
  21. var string3 = "dsadas\tdasda";
  22. var string4 = "Stoyan " + "Cheresharov";
  23.  
  24. var text = "testing: 1, 2, 3"; // Sample text
  25. var pattern = /\d+/g // Matches all instances of one or more digits
  26.  
  27. var a = 4;
  28.  
  29. var global = this;
  30.  
  31. var myName = '';
  32.  
  33. string4.charAt = function(){};
  34.  
  35. console.log(typeof number);
  36. console.log(typeof string);
  37. console.log(typeof bool);
  38. console.log(typeof null);
  39. console.log(typeof undefined);
  40. console.log(typeof stoyan);
  41. console.log(stoyan.name);
  42. console.log(stoyan["name"]);
  43. console.log(typeof primes);
  44. console.log(primes.length);
  45. console.log(typeof MyFunction);
  46. console.log(hex);
  47. console.log(oct);
  48. console.log(t);
  49. console.log(hex/oct);
  50. console.log(Math.random());
  51. console.log(12/0 === Infinity);
  52. console.log(then);
  53. console.log(string2);
  54. console.log(string3);
  55. console.log(string4.length);
  56. console.log(string4.charAt(0));
  57. console.log(string4[0]);
  58. console.log(text.match(pattern));
  59. console.log( a == 4 );
  60. console.log(global);
  61. console.log("" === 0);
  62. console.log(0 == false);
  63. console.log(Number(string4)); // +number
  64.  
  65. console.log(typeof String(number));
  66. console.log(Boolean(string4));
  67. console.log(Boolean(''));
  68. console.log( string4 + number);
  69. console.log(typeof myObject2.valueOf());
  70.  
  71. var scope = "global scope"; // A global variable
  72. function checkscope() {
  73.      // A local variable
  74.     var scope = "local scope";
  75.    
  76.     console.log(scope);
  77. }
  78. console.log(checkscope()); // => "nested scope"
  79.  
  80. 3;
  81. scope;
  82.  
  83. var myObject10 = {a: 2, b: 3};
  84. var myArray10 = ["first", "second", "tird"];
  85. var square = function(x) { return x * x; };
  86. square(2);
  87. delete myObject10.a;
  88.  
  89. console.log('a' in myObject10);
  90.  
  91. delete myArray10[1];
  92.  
  93. console.log(myArray10[1]);
  94.  
  95. console.log(myArray10.length);
  96. console.log(1 + "Stoyan");
  97.  
  98. var forShift  = -120;
  99. console.log(forShift >> 2);
  100. console.log(forShift >>> 2);
  101. console.log(forShift << 2);
  102.  
  103. console.log({} instanceof Object);
  104.  
  105. console.log(0 === Number("0"));
  106.  
  107. var test = {a:1} && 0;
  108.  
  109. console.log(!!({a:1} && 0));
  110.  
  111. console.log(test);
  112.  
  113. var test1 = null;
  114. var test2 = undefined;
  115.  
  116. // var result;
  117. var result = test1 || test2;
  118. // if (test1) result = test1;
  119. // if (test2) result = test2;
  120.  
  121. console.log(result);
  122. // !(p && q) === !p || !q
  123. // !(p || q) === !p && !q
  124.  
  125. // eval("alert('Hello World')");
  126. {
  127. x = Math.PI;
  128. cx = Math.cos(x);
  129. console.log("cos(?) = " + cx);
  130. }
  131.  
  132. var n = 1;
  133.  
  134. if (n == 1) {
  135. // Execute code block #1
  136. }
  137. else if (n == 2) {
  138. // Execute code block #2
  139. }
  140. else if (n == 3) {
  141. // Execute code block #3
  142. }
  143. else {
  144. // If all else fails, execute block #4
  145. }
  146.  
  147. switch(n) {
  148. case 1: // Start here if n == 1
  149. // Execute code block #1.
  150. break;
  151. // Stop here
  152. case 2: // Start here if n == 2
  153. // Execute code block #2.
  154. break; // Stop here
  155. case 3: // Start here if n == 3
  156. // Execute code block #3.
  157. break; // Stop here
  158. default: // If all else fails...
  159. // Execute code block #4.
  160. break; // stop here
  161. }
  162.  
  163. var count = 0;
  164. var limit = 10;
  165. while ( count < limit ) {
  166.     console.log(count);
  167.     count++;
  168. }
  169.  
  170. count = 10;
  171.  
  172. do {
  173.     console.log("do while", count);
  174.     count++;
  175. } while (count < limit);
  176.  
  177.  
  178. for(var count = 0; count < 10; count++) {
  179.     console.log(count);
  180. }
  181.  
  182. var o = {x:1, y:2, z:3};
  183. var a = [], i = 0;
  184. for(a[i++] in o) /* empty */;
  185.  
  186. console.log(a[0]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement