Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Operators
- *
- * Operators act on our data types. There are: */
- // Assignment operators, such as: =, +=, -=
- var assign = 1;
- console.log(assign += 1); // here we've added one
- console.log(assign -= 2); // here we've removed the initial assignment of one
- // and the prior modification of one to equal zero
- // Comparison operators, such as <, >, <=, >=
- // these operators return a boolean value
- console.log(1 > 2);
- console.log(1 < 2);
- // Strict comparison operators, such as ===, !==
- // These also return booleans, but only if both values being compared are
- // of the same data type
- console.log(1 === "1");
- console.log(1 === 1);
- console.log("a" === "a");
- console.log("a" !== "a"); // exclamation point is "not", is a logical operator
- // Logical Operators, &&, ||, !
- // These add an element of logic to our statements
- console.log(1 < 2 || 3 > 4); // this is true because one of our statements
- // is true; this is the "or" operator
- console.log(1 < 2 && 3 > 4); // this is false because one of our statements
- // is false; this is is "and" operator
- console.log(!true); // this is false because the "bang" operator has reversed
- // the binary "true"
- // Arithmetic operators perform arithmetic operations on data, +, -, *, /
- console.log(1 + 1);
- console.log(1 - 1);
- console.log(1 * 2);
- console.log(6 / 2);
- console.log(4 % 3); // modulus % returns the remainder of a division operation
- // Binary operators, !, typeof, -
- var a = 1;
- console.log(-a); // negates value
- var b = 1;
- console.log(!b); // bang operator reverses boolean value
- var c = 1;
- console.log(typeof c); // returns data type
- // Ternary operator, ?
- console.log(1 ? 2 : 3);
- </script>
- <script id="jsbin-source-javascript" type="text/javascript">/* Operators
- *
- * Operators act on our data types. There are: */
- // Assignment operators, such as: =, +=, -=
- var assign = 1;
- console.log(assign += 1); // here we've added one
- console.log(assign -= 2); // here we've removed the initial assignment of one
- // and the prior modification of one to equal zero
- // Comparison operators, such as <, >, <=, >=
- // these operators return a boolean value
- console.log(1 > 2);
- console.log(1 < 2);
- // Strict comparison operators, such as ===, !==
- // These also return booleans, but only if both values being compared are
- // of the same data type
- console.log(1 === "1");
- console.log(1 === 1);
- console.log("a" === "a");
- console.log("a" !== "a"); // exclamation point is "not", is a logical operator
- // Logical Operators, &&, ||, !
- // These add an element of logic to our statements
- console.log(1 < 2 || 3 > 4); // this is true because one of our statements
- // is true; this is the "or" operator
- console.log(1 < 2 && 3 > 4); // this is false because one of our statements
- // is false; this is is "and" operator
- console.log(!true); // this is false because the "bang" operator has reversed
- // the binary "true"
- // Arithmetic operators perform arithmetic operations on data, +, -, *, /
- console.log(1 + 1);
- console.log(1 - 1);
- console.log(1 * 2);
- console.log(6 / 2);
- console.log(4 % 3); // modulus % returns the remainder of a division operation
- // Binary operators, !, typeof, -
- var a = 1;
- console.log(-a); // negates value
- var b = 1;
- console.log(!b); // bang operator reverses boolean value
- var c = 1;
- console.log(typeof c); // returns data type
- // Ternary operator, ?
- console.log(1 ? 2 : 3);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement