Skip to content

Instantly share code, notes, and snippets.

@ndonolli
Forked from anonymous/index.html
Last active June 26, 2016 18:27
Show Gist options
  • Save ndonolli/99fef109aa6fc237ba7b11773f7c431e to your computer and use it in GitHub Desktop.
Save ndonolli/99fef109aa6fc237ba7b11773f7c431e to your computer and use it in GitHub Desktop.
JS Bin// source https://jsbin.com/kasokaj
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
/*
=========
OPERATORS
=========
Operations can be performed on data using operators. Javascript has unary and binary operators, as well as one turnary operator. All operators must be used on an operand, which can be a Number, String, or other data type.
Assignment (=)
--------------
The assignment operator is notated by a single equals sign (=) and assigns an operand to reference another one. We have seen this before in declaring and initializing variables.
*/
var a = "Steve McQueen";
var b = a;
console.log(b);
// > "Steve McQueen"
// Above, we assigned var a to a string, then assigned a new variable b to a. Now, variable b is assigned to the value of variable a. Note that since we are dealing with primitive data, changing variable a will not affect variable b.
var a = "Evil Kenevil";
console.log(b);
// > "Steve McQueen"
/*
Arithmetic ( +, -, /, *)
----------
Basic arithmetic functions, like plus, minus, and divide, are operands that can be used on Numbers and even Strings.
*/
console.log(3 + 3);
// > 6
console.log(4 * 2 * 3);
// > 24
// You can use the ( + ) operator to concatenate strings.
console.log("Mr. " + "Poopy Butthole" );
// > "Mr. Poopy Butthole"
// There exist other arithmetic operators in javascript as well.
// Modulus ( % ) returns the remainder when divided.
console.log(10 % 3);
// > 1
// Increment increases the value by 1
var x = 3;
++x;
console.log(x);
// > 4
// The minus operator can also be used to negate values.
console.log(-x);
// > -4
/*
Comparison
----------
Operators under this category compare the values of two operands and return a true or false value.
*/
// Equal ( == ) returns true if the operands are equal in value. Not equal is represented as ( != ).
console.log(3 == 3);
// > true
console.log(3 != 3);
// > false
// Using a strict comparison ( === ) will not only compare the values, but also the data type as well.
console.log(3 === 3);
// > true
console.log(3 === '3');
// > false
/*
Logical operators
-----------------
To compare two boolean values in order to return another conditional boolean we use logical operators. In Javascript there exist AND ( && ), OR ( || ), and NOT ( ! ). AND will return true if both operands are true. OR will return true if at least one operator is true. NOT will negate the boolean value.
*/
var isSheHot = true;
var isSheSingle = false;
console.log(isSheHot && isSheSingle);
// > false
console.log(isSheHot || isSheSingle);
// > true
console.log(isSheHot && !isSheSingle);
// > true
/*
Turnary
-------
Lastly, there is one turnary operator in javascript ( ? ). This operator takes one condition and assigns one of two other operands depending on the boolean value of the condition.
*/
var age = 18;
var oneBeerPlease = (age >= 21) ? "Have a beer" : "Get lost, kid";
console.log(oneBeerPlease);
// > "Get lost, kid"
</script>
<script id="jsbin-source-javascript" type="text/javascript">/*
=========
OPERATORS
=========
Operations can be performed on data using operators. Javascript has unary and binary operators, as well as one turnary operator. All operators must be used on an operand, which can be a Number, String, or other data type.
Assignment (=)
--------------
The assignment operator is notated by a single equals sign (=) and assigns an operand to reference another one. We have seen this before in declaring and initializing variables.
*/
var a = "Steve McQueen";
var b = a;
console.log(b);
// > "Steve McQueen"
// Above, we assigned var a to a string, then assigned a new variable b to a. Now, variable b is assigned to the value of variable a. Note that since we are dealing with primitive data, changing variable a will not affect variable b.
var a = "Evil Kenevil";
console.log(b);
// > "Steve McQueen"
/*
Arithmetic ( +, -, /, *)
----------
Basic arithmetic functions, like plus, minus, and divide, are operands that can be used on Numbers and even Strings.
*/
console.log(3 + 3);
// > 6
console.log(4 * 2 * 3);
// > 24
// You can use the ( + ) operator to concatenate strings.
console.log("Mr. " + "Poopy Butthole" );
// > "Mr. Poopy Butthole"
// There exist other arithmetic operators in javascript as well.
// Modulus ( % ) returns the remainder when divided.
console.log(10 % 3);
// > 1
// Increment increases the value by 1
var x = 3;
++x;
console.log(x);
// > 4
// The minus operator can also be used to negate values.
console.log(-x);
// > -4
/*
Comparison
----------
Operators under this category compare the values of two operands and return a true or false value.
*/
// Equal ( == ) returns true if the operands are equal in value. Not equal is represented as ( != ).
console.log(3 == 3);
// > true
console.log(3 != 3);
// > false
// Using a strict comparison ( === ) will not only compare the values, but also the data type as well.
console.log(3 === 3);
// > true
console.log(3 === '3');
// > false
/*
Logical operators
-----------------
To compare two boolean values in order to return another conditional boolean we use logical operators. In Javascript there exist AND ( && ), OR ( || ), and NOT ( ! ). AND will return true if both operands are true. OR will return true if at least one operator is true. NOT will negate the boolean value.
*/
var isSheHot = true;
var isSheSingle = false;
console.log(isSheHot && isSheSingle);
// > false
console.log(isSheHot || isSheSingle);
// > true
console.log(isSheHot && !isSheSingle);
// > true
/*
Turnary
-------
Lastly, there is one turnary operator in javascript ( ? ). This operator takes one condition and assigns one of two other operands depending on the boolean value of the condition.
*/
var age = 18;
var oneBeerPlease = (age >= 21) ? "Have a beer" : "Get lost, kid";
console.log(oneBeerPlease);
// > "Get lost, kid"
</script></body>
</html>
/*
=========
OPERATORS
=========
Operations can be performed on data using operators. Javascript has unary and binary operators,
as well as one turnary operator. All operators must be used on an operand, which can be a
Number, String, or other data type.
Assignment (=)
--------------
The assignment operator is notated by a single equals sign (=) and assigns an operand to
reference another one. We have seen this before in declaring and initializing variables.
*/
var a = "Steve McQueen";
var b = a;
console.log(b);
// > "Steve McQueen"
// Above, we assigned var a to a string, then assigned a new variable b to a. Now, variable b
// is assigned to the value of variable a. Note that since we are dealing with primitive data,
// changing variable a will not affect variable b.
var a = "Evil Kenevil";
console.log(b);
// > "Steve McQueen"
/*
Arithmetic ( +, -, /, *)
----------
Basic arithmetic functions, like plus, minus, and divide, are operands that can be used on
Numbers and even Strings.
*/
console.log(3 + 3);
// > 6
console.log(4 * 2 * 3);
// > 24
// You can use the ( + ) operator to concatenate strings.
console.log("Mr. " + "Poopy Butthole" );
// > "Mr. Poopy Butthole"
// There exist other arithmetic operators in javascript as well.
// Modulus ( % ) returns the remainder when divided.
console.log(10 % 3);
// > 1
// Increment increases the value by 1
var x = 3;
++x;
console.log(x);
// > 4
// The minus operator can also be used to negate values.
console.log(-x);
// > -4
/*
Comparison ( ==, !=, === )
----------
Operators under this category compare the values of two operands and return a true or
false value.
*/
// Equal ( == ) returns true if the operands are equal in value. Not equal is represented
// as ( != ).
console.log(3 == 3);
// > true
console.log(3 != 3);
// > false
// Using a strict comparison ( === ) will not only compare the values, but also the data
// type as well.
console.log(3 === 3);
// > true
console.log(3 === '3');
// > false
/*
Logical operators ( &&, || )
-----------------
To compare two boolean values in order to return another conditional boolean we use logical
operators. In Javascript there exist AND ( && ), OR ( || ), and NOT ( ! ). AND will return
true if both operands are true. OR will return true if at least one operator is true.
NOT will negate the boolean value.
*/
var isSheHot = true;
var isSheSingle = false;
console.log(isSheHot && isSheSingle);
// > false
console.log(isSheHot || isSheSingle);
// > true
console.log(isSheHot && !isSheSingle);
// > true
/*
Turnary
-------
Lastly, there is one turnary operator in javascript ( ? ). This operator takes one condition
and assigns one of two other operands depending on the boolean value of the condition.
*/
var age = 18;
var oneBeerPlease = (age >= 21) ? "Have a beer" : "Get lost, kid";
console.log(oneBeerPlease);
// > "Get lost, kid"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment