Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. /*
  2. * Operators
  3. *
  4. * Operators act on our data types. There are: */
  5.  
  6. // Assignment operators, such as: =, +=, -=
  7.  
  8. var assign = 1;
  9. console.log(assign += 1); // here we've added one
  10. console.log(assign -= 2); // here we've removed the initial assignment of one
  11. // and the prior modification of one to equal zero
  12.  
  13. // Comparison operators, such as <, >, <=, >=
  14. // these operators return a boolean value
  15.  
  16. console.log(1 > 2);
  17. console.log(1 < 2);
  18.  
  19. // Strict comparison operators, such as ===, !==
  20. // These also return booleans, but only if both values being compared are
  21. // of the same data type
  22.  
  23. console.log(1 === "1");
  24. console.log(1 === 1);
  25. console.log("a" === "a");
  26. console.log("a" !== "a"); // exclamation point is "not", is a logical operator
  27.  
  28. // Logical Operators, &&, ||, !
  29. // These add an element of logic to our statements
  30.  
  31. console.log(1 < 2 || 3 > 4); // this is true because one of our statements
  32. // is true; this is the "or" operator
  33.  
  34. console.log(1 < 2 && 3 > 4); // this is false because one of our statements
  35. // is false; this is is "and" operator
  36.  
  37. console.log(!true); // this is false because the "bang" operator has reversed
  38. // the binary "true"
  39.  
  40. // Arithmetic operators perform arithmetic operations on data, +, -, *, /
  41.  
  42. console.log(1 + 1);
  43. console.log(1 - 1);
  44. console.log(1 * 2);
  45. console.log(6 / 2);
  46. console.log(4 % 3); // modulus % returns the remainder of a division operation
  47.  
  48. // Binary operators, !, typeof, -
  49.  
  50. var a = 1;
  51. console.log(-a); // negates value
  52.  
  53. var b = 1;
  54. console.log(!b); // bang operator reverses boolean value
  55.  
  56. var c = 1;
  57. console.log(typeof c); // returns data type
  58.  
  59. // Ternary operator, ?
  60.  
  61. console.log(1 ? 2 : 3);
  62. </script>
  63.  
  64.  
  65.  
  66. <script id="jsbin-source-javascript" type="text/javascript">/* Operators
  67. *
  68. * Operators act on our data types. There are: */
  69.  
  70. // Assignment operators, such as: =, +=, -=
  71.  
  72. var assign = 1;
  73. console.log(assign += 1); // here we've added one
  74. console.log(assign -= 2); // here we've removed the initial assignment of one
  75. // and the prior modification of one to equal zero
  76.  
  77. // Comparison operators, such as <, >, <=, >=
  78. // these operators return a boolean value
  79.  
  80. console.log(1 > 2);
  81. console.log(1 < 2);
  82.  
  83. // Strict comparison operators, such as ===, !==
  84. // These also return booleans, but only if both values being compared are
  85. // of the same data type
  86.  
  87. console.log(1 === "1");
  88. console.log(1 === 1);
  89. console.log("a" === "a");
  90. console.log("a" !== "a"); // exclamation point is "not", is a logical operator
  91.  
  92. // Logical Operators, &&, ||, !
  93. // These add an element of logic to our statements
  94.  
  95. console.log(1 < 2 || 3 > 4); // this is true because one of our statements
  96. // is true; this is the "or" operator
  97.  
  98. console.log(1 < 2 && 3 > 4); // this is false because one of our statements
  99. // is false; this is is "and" operator
  100.  
  101. console.log(!true); // this is false because the "bang" operator has reversed
  102. // the binary "true"
  103.  
  104. // Arithmetic operators perform arithmetic operations on data, +, -, *, /
  105.  
  106. console.log(1 + 1);
  107. console.log(1 - 1);
  108. console.log(1 * 2);
  109. console.log(6 / 2);
  110. console.log(4 % 3); // modulus % returns the remainder of a division operation
  111.  
  112. // Binary operators, !, typeof, -
  113.  
  114. var a = 1;
  115. console.log(-a); // negates value
  116.  
  117. var b = 1;
  118. console.log(!b); // bang operator reverses boolean value
  119.  
  120. var c = 1;
  121. console.log(typeof c); // returns data type
  122.  
  123. // Ternary operator, ?
  124.  
  125. console.log(1 ? 2 : 3);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement