Skip to content

Instantly share code, notes, and snippets.

@LindseyCason
Last active July 23, 2017 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LindseyCason/846343d25f24473c4e014bb71023e713 to your computer and use it in GitHub Desktop.
Save LindseyCason/846343d25f24473c4e014bb71023e713 to your computer and use it in GitHub Desktop.
JS Bin// source https://jsbin.com/numowi
<!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">
/*Data Types:
*
*In JavaScript variables can be assigned various Data Types. Some of those
*Data Types include: Numbers, Strings, Booleans, Arrays, Objects, Functions,
*Undefine, Null, Nan, Google Infinity and -Infinity.
*
*/
//Numbers: In JavaScript there is only one type of number. These numbers
//can be assigned to variables written with or without decimals.
//ex.
var number = 3;
var num1= 3.14;
//Strings: Strings are characters strung together to form a string. Strings can be comprised
// of anything. They do not have to be alphabetical. To make a data type a string they must be
// surrounded by "" or ''. Inside of a string, you can use quotes or apostrophes as long as the
// surrounding "" or '' are different. Strings can be numbers and symbols as well. Multiple
// strings can be "added" together by concatination. If a number is added to a string,
//JS will treat the number as a string.
//ex.
var string = "Lindsey";
var string = "143";
var string = "#L1ND5EY";
console.log("Lindsey" + " Cason"); //"Lindsey Cason"
console.log(15 + " Lindsey"); //"15 Lindsey"
//Boolean: Boolean is a data type that only returns the value of true or false.
//If the input condition is a comparison then the boolean will return
//true or false based on this comparison. Anything that does not have a real
//value will return false as well./*
//ex,
console.log(143<153); // comparison // true
console.log(153<143); // comparison // false
var x = 0;
console.log(Boolean(x)); // 0 has no value // false
var v = -1;
console.log(Boolean(v)); // -1 has value // true
var y = "H";
console.log(Boolean(y)); // "H" has value // true
var z = 25 / "H";
console.log(Boolean(z)); // result is NaN, no value // false
var w = "";
console.log(Boolean(w)); // empty string has no value // false
var u
console.log(Boolean(u)); // undefined has no value // false
var t = null;
console.log(Boolean(t)); // null has no value //false
var s = false;
console.log(Boolean(s)); // false has no value // false
//Array: Arrays are a data type that hold multiple values grouped together.
//Arrays can hold many different TYPES of values as well. They are a
//zero indexed list which means that each element can be accessed by
//it's index number. The index numbers start counting at 0.
//Arrays are encompased by [] around the elements in the array.
//You can also place an array inside of an array.
//ex.
var array1 = ["Lindsey" , "Melissa", "Sandy", "Duke"];
console.log(array1); // ["Lindsey", "Melissa", "Sandy", "Duke"]
//You can add elements to the end of an array using the push method.
//ex.
array1.push("Sebastian");
console.log(array1); // ["Lindsey", "Melissa", "Sandy", "Duke", "Sebastian"]
//You can remove an element from the end of the array by using the pop method.
array1.pop();
console.log(array1); // ["Lindsey", "Melissa", "Sandy", "Duke"]
//You can also remove an element from the array by using the splice method and
//indicating the number of items you want to remain in the element.
array1.splice(2);
console.log(array1); // ["Lindsey", "Melissa"]
//You can find out how many items are in your array by using the length method.
var array1 = ["Lindsey" , "Melissa", "Sandy", "Duke"];
console.log(array1.length); // 4
//You can access a specific element in an array by using the index number.
var array1 = ["Lindsey" , "Melissa", "Sandy", "Duke"];
console.log(array1[2]); // Sandy (because we start counting at 0)
//Objects: Objects are a group of key/value pairs. They are variables that
//contain many values. These values can be any type of data. Objects are
//declared by encompassing them in {} and adding the key value pairs in between.
//Each Key/Value pair must be seperated by a comma. In the example below
//the key is name and the value is "Lindsey".
//ex.
var person ={
name: "Lindsey",
age: 102,
height: "66in",
animals: ["Sandy", "Duke", "Sebastian", "CoCo"],
}
//You can access the items in the Object by pointing to its key.
console.log(person.name); // "Lindsey"
//If your object contains an array, you can access that array by pointing
//to the key and then to the index of the item you want.
console.log(person.animals[2]); // "Sebastian"
//You can also add key/value pairs to the object by using dot notation method.
//Once you name the object, you add the new key and assign the new value.
//object.newKey = newValue;.
person.job = "Student";
console.log(person); //
// [object Object] {
// age: 102,
// animals: ["Sandy", "Duke", "Sebastian", "CoCo"],
// height: "66in",
// job: "Student",
// name: "Lindsey"
// }
//You can also remove a key/value pair by using delete operator and then dot notation
//for the object and the key. delete object.key;.
delete person.name;
console.log(person); //
// [object Object] {
// age: 102,
// animals: ["Sandy", "Duke", "Sebastian", "CoCo"],
// height: "66in",
// job: "Student"
// }
//Function: A function is a block of code designed to perform
//a specific task. The function must be called or invoked for JavaScript
//to execute the function. You define a function by using the keyword
//function followed the name of your function and parentheses. Inside
//the parentheses the paremeters of the function are placed and seperated
//by a comma. The code that will be ran in the function will be placed
//inside curly brackets {}. The function will be called/invoked outside of
//the closing curly brakcet. After the function is called, it stops at a
//return statement. The result of the function will return to the
//statement that originally called/invoked the function.
//ex.
function myFunc(a,b) {
return a + b;
}
var x = myFunc(2,3); // assigning a var stores the value here.
//passing in 2 and 3 in the parameters when we
// call the function gives us the values to work with.
console.log(x); // returns 5
//We use functions so we can reuse the code multiple times. We only
//have to define the code once and then we can pass in different parameters
//to get different results. We already have a function above. I can use that
//same function again. See below
//ex.
var y = myFunc(100,423); //calling the function() with different parameters
console.log(y); //returns 523
//Undefined: Any variable that does not have a value is "undefined".
//ex.
var cat; //there is no value assigned here
console.log(cat); //returns undefined
//Null: Null means the value is nothing. You can empty an object
//by assigning it to null.
//ex.
var dog = null;
console.log(dog); //returns null
//NaN: NaN means "Not a Number". This is the result you will get
//when a number is not a legal number. If you try to do arithmetic with
//a word instead of a number you will see "NaN" -Not a Number.
//ex.
var bird = 23 * "robin"; // "robin" is a string and Not a Number
console.log(bird); // returns NaN
var bird = 23 * 2; //both are numbers here
console.log(bird); //returns 46
//Infinity & -Infinity: Infinity is a numeric value that represents
//positive infinity. -Infinity is a numeric value that represents
//negative infinity.
//Infinity is displayed when a number exceeds the upper limit of
//the floating point numbers, which is 1.797693134862315E+308
//-Infinity is displayed when a number exceeds the lower limit of the floating
//point numbers, which is -1.797693134862316E+308.
//Anything you devide by zero will give you infinity/-infinity.
//ex.
var inf = 5 / 0;
console.log(inf); //returns infinity
var inf = -5 / 0;
console.log(inf); // returns -infinity
//
//
//
//
//
</script>
<script id="jsbin-source-javascript" type="text/javascript">/*Data Types:
*
*In JavaScript variables can be assigned various Data Types. Some of those
*Data Types include: Numbers, Strings, Booleans, Arrays, Objects, Functions,
*Undefine, Null, Nan, Google Infinity and -Infinity.
*
*/
//Numbers: In JavaScript there is only one type of number. These numbers
//can be assigned to variables written with or without decimals.
//ex.
var number = 3;
var num1= 3.14;
//Strings: Strings are characters strung together to form a string. Strings can be comprised
// of anything. They do not have to be alphabetical. To make a data type a string they must be
// surrounded by "" or ''. Inside of a string, you can use quotes or apostrophes as long as the
// surrounding "" or '' are different. Strings can be numbers and symbols as well. Multiple
// strings can be "added" together by concatination. If a number is added to a string,
//JS will treat the number as a string.
//ex.
var string = "Lindsey";
var string = "143";
var string = "#L1ND5EY";
console.log("Lindsey" + " Cason"); //"Lindsey Cason"
console.log(15 + " Lindsey"); //"15 Lindsey"
//Boolean: Boolean is a data type that only returns the value of true or false.
//If the input condition is a comparison then the boolean will return
//true or false based on this comparison. Anything that does not have a real
//value will return false as well./*
//ex,
console.log(143<153); // comparison // true
console.log(153<143); // comparison // false
var x = 0;
console.log(Boolean(x)); // 0 has no value // false
var v = -1;
console.log(Boolean(v)); // -1 has value // true
var y = "H";
console.log(Boolean(y)); // "H" has value // true
var z = 25 / "H";
console.log(Boolean(z)); // result is NaN, no value // false
var w = "";
console.log(Boolean(w)); // empty string has no value // false
var u
console.log(Boolean(u)); // undefined has no value // false
var t = null;
console.log(Boolean(t)); // null has no value //false
var s = false;
console.log(Boolean(s)); // false has no value // false
//Array: Arrays are a data type that hold multiple values grouped together.
//Arrays can hold many different TYPES of values as well. They are a
//zero indexed list which means that each element can be accessed by
//it's index number. The index numbers start counting at 0.
//Arrays are encompased by [] around the elements in the array.
//You can also place an array inside of an array.
//ex.
var array1 = ["Lindsey" , "Melissa", "Sandy", "Duke"];
console.log(array1); // ["Lindsey", "Melissa", "Sandy", "Duke"]
//You can add elements to the end of an array using the push method.
//ex.
array1.push("Sebastian");
console.log(array1); // ["Lindsey", "Melissa", "Sandy", "Duke", "Sebastian"]
//You can remove an element from the end of the array by using the pop method.
array1.pop();
console.log(array1); // ["Lindsey", "Melissa", "Sandy", "Duke"]
//You can also remove an element from the array by using the splice method and
//indicating the number of items you want to remain in the element.
array1.splice(2);
console.log(array1); // ["Lindsey", "Melissa"]
//You can find out how many items are in your array by using the length method.
var array1 = ["Lindsey" , "Melissa", "Sandy", "Duke"];
console.log(array1.length); // 4
//You can access a specific element in an array by using the index number.
var array1 = ["Lindsey" , "Melissa", "Sandy", "Duke"];
console.log(array1[2]); // Sandy (because we start counting at 0)
//Objects: Objects are a group of key/value pairs. They are variables that
//contain many values. These values can be any type of data. Objects are
//declared by encompassing them in {} and adding the key value pairs in between.
//Each Key/Value pair must be seperated by a comma. In the example below
//the key is name and the value is "Lindsey".
//ex.
var person ={
name: "Lindsey",
age: 102,
height: "66in",
animals: ["Sandy", "Duke", "Sebastian", "CoCo"],
}
//You can access the items in the Object by pointing to its key.
console.log(person.name); // "Lindsey"
//If your object contains an array, you can access that array by pointing
//to the key and then to the index of the item you want.
console.log(person.animals[2]); // "Sebastian"
//You can also add key/value pairs to the object by using dot notation method.
//Once you name the object, you add the new key and assign the new value.
//object.newKey = newValue;.
person.job = "Student";
console.log(person); //
// [object Object] {
// age: 102,
// animals: ["Sandy", "Duke", "Sebastian", "CoCo"],
// height: "66in",
// job: "Student",
// name: "Lindsey"
// }
//You can also remove a key/value pair by using delete operator and then dot notation
//for the object and the key. delete object.key;.
delete person.name;
console.log(person); //
// [object Object] {
// age: 102,
// animals: ["Sandy", "Duke", "Sebastian", "CoCo"],
// height: "66in",
// job: "Student"
// }
//Function: A function is a block of code designed to perform
//a specific task. The function must be called or invoked for JavaScript
//to execute the function. You define a function by using the keyword
//function followed the name of your function and parentheses. Inside
//the parentheses the paremeters of the function are placed and seperated
//by a comma. The code that will be ran in the function will be placed
//inside curly brackets {}. The function will be called/invoked outside of
//the closing curly brakcet. After the function is called, it stops at a
//return statement. The result of the function will return to the
//statement that originally called/invoked the function.
//ex.
function myFunc(a,b) {
return a + b;
}
var x = myFunc(2,3); // assigning a var stores the value here.
//passing in 2 and 3 in the parameters when we
// call the function gives us the values to work with.
console.log(x); // returns 5
//We use functions so we can reuse the code multiple times. We only
//have to define the code once and then we can pass in different parameters
//to get different results. We already have a function above. I can use that
//same function again. See below
//ex.
var y = myFunc(100,423); //calling the function() with different parameters
console.log(y); //returns 523
//Undefined: Any variable that does not have a value is "undefined".
//ex.
var cat; //there is no value assigned here
console.log(cat); //returns undefined
//Null: Null means the value is nothing. You can empty an object
//by assigning it to null.
//ex.
var dog = null;
console.log(dog); //returns null
//NaN: NaN means "Not a Number". This is the result you will get
//when a number is not a legal number. If you try to do arithmetic with
//a word instead of a number you will see "NaN" -Not a Number.
//ex.
var bird = 23 * "robin"; // "robin" is a string and Not a Number
console.log(bird); // returns NaN
var bird = 23 * 2; //both are numbers here
console.log(bird); //returns 46
//Infinity & -Infinity: Infinity is a numeric value that represents
//positive infinity. -Infinity is a numeric value that represents
//negative infinity.
//Infinity is displayed when a number exceeds the upper limit of
//the floating point numbers, which is 1.797693134862315E+308
//-Infinity is displayed when a number exceeds the lower limit of the floating
//point numbers, which is -1.797693134862316E+308.
//Anything you devide by zero will give you infinity/-infinity.
//ex.
var inf = 5 / 0;
console.log(inf); //returns infinity
var inf = -5 / 0;
console.log(inf); // returns -infinity
//
//
//
//
//</script></body>
</html>
/*Data Types:
*
*In JavaScript variables can be assigned various Data Types. Some of those
*Data Types include: Numbers, Strings, Booleans, Arrays, Objects, Functions,
*Undefine, Null, Nan, Google Infinity and -Infinity.
*
*/
//Numbers: In JavaScript there is only one type of number. These numbers
//can be assigned to variables written with or without decimals.
//ex.
var number = 3;
var num1= 3.14;
//Strings: Strings are characters strung together to form a string. Strings can be comprised
// of anything. They do not have to be alphabetical. To make a data type a string they must be
// surrounded by "" or ''. Inside of a string, you can use quotes or apostrophes as long as the
// surrounding "" or '' are different. Strings can be numbers and symbols as well. Multiple
// strings can be "added" together by concatination. If a number is added to a string,
//JS will treat the number as a string.
//ex.
var string = "Lindsey";
var string = "143";
var string = "#L1ND5EY";
console.log("Lindsey" + " Cason"); //"Lindsey Cason"
console.log(15 + " Lindsey"); //"15 Lindsey"
//Boolean: Boolean is a data type that only returns the value of true or false.
//If the input condition is a comparison then the boolean will return
//true or false based on this comparison. Anything that does not have a real
//value will return false as well./*
//ex,
console.log(143<153); // comparison // true
console.log(153<143); // comparison // false
var x = 0;
console.log(Boolean(x)); // 0 has no value // false
var v = -1;
console.log(Boolean(v)); // -1 has value // true
var y = "H";
console.log(Boolean(y)); // "H" has value // true
var z = 25 / "H";
console.log(Boolean(z)); // result is NaN, no value // false
var w = "";
console.log(Boolean(w)); // empty string has no value // false
var u
console.log(Boolean(u)); // undefined has no value // false
var t = null;
console.log(Boolean(t)); // null has no value //false
var s = false;
console.log(Boolean(s)); // false has no value // false
//Array: Arrays are a data type that hold multiple values grouped together.
//Arrays can hold many different TYPES of values as well. They are a
//zero indexed list which means that each element can be accessed by
//it's index number. The index numbers start counting at 0.
//Arrays are encompased by [] around the elements in the array.
//You can also place an array inside of an array.
//ex.
var array1 = ["Lindsey" , "Melissa", "Sandy", "Duke"];
console.log(array1); // ["Lindsey", "Melissa", "Sandy", "Duke"]
//You can add elements to the end of an array using the push method.
//ex.
array1.push("Sebastian");
console.log(array1); // ["Lindsey", "Melissa", "Sandy", "Duke", "Sebastian"]
//You can remove an element from the end of the array by using the pop method.
array1.pop();
console.log(array1); // ["Lindsey", "Melissa", "Sandy", "Duke"]
//You can also remove an element from the array by using the splice method and
//indicating the number of items you want to remain in the element.
array1.splice(2);
console.log(array1); // ["Lindsey", "Melissa"]
//You can find out how many items are in your array by using the length method.
var array1 = ["Lindsey" , "Melissa", "Sandy", "Duke"];
console.log(array1.length); // 4
//You can access a specific element in an array by using the index number.
var array1 = ["Lindsey" , "Melissa", "Sandy", "Duke"];
console.log(array1[2]); // Sandy (because we start counting at 0)
//Objects: Objects are a group of key/value pairs. They are variables that
//contain many values. These values can be any type of data. Objects are
//declared by encompassing them in {} and adding the key value pairs in between.
//Each Key/Value pair must be seperated by a comma. In the example below
//the key is name and the value is "Lindsey".
//ex.
var person ={
name: "Lindsey",
age: 102,
height: "66in",
animals: ["Sandy", "Duke", "Sebastian", "CoCo"],
}
//You can access the items in the Object by pointing to its key.
console.log(person.name); // "Lindsey"
//If your object contains an array, you can access that array by pointing
//to the key and then to the index of the item you want.
console.log(person.animals[2]); // "Sebastian"
//You can also add key/value pairs to the object by using dot notation method.
//Once you name the object, you add the new key and assign the new value.
//object.newKey = newValue;.
person.job = "Student";
console.log(person); //
// [object Object] {
// age: 102,
// animals: ["Sandy", "Duke", "Sebastian", "CoCo"],
// height: "66in",
// job: "Student",
// name: "Lindsey"
// }
//You can also remove a key/value pair by using delete operator and then dot notation
//for the object and the key. delete object.key;.
delete person.name;
console.log(person); //
// [object Object] {
// age: 102,
// animals: ["Sandy", "Duke", "Sebastian", "CoCo"],
// height: "66in",
// job: "Student"
// }
//Function: A function is a block of code designed to perform
//a specific task. The function must be called or invoked for JavaScript
//to execute the function. You define a function by using the keyword
//function followed the name of your function and parentheses. Inside
//the parentheses the paremeters of the function are placed and seperated
//by a comma. The code that will be ran in the function will be placed
//inside curly brackets {}. The function will be called/invoked outside of
//the closing curly brakcet. After the function is called, it stops at a
//return statement. The result of the function will return to the
//statement that originally called/invoked the function.
//ex.
function myFunc(a,b) {
return a + b;
}
var x = myFunc(2,3); // assigning a var stores the value here.
//passing in 2 and 3 in the parameters when we
// call the function gives us the values to work with.
console.log(x); // returns 5
//We use functions so we can reuse the code multiple times. We only
//have to define the code once and then we can pass in different parameters
//to get different results. We already have a function above. I can use that
//same function again. See below
//ex.
var y = myFunc(100,423); //calling the function() with different parameters
console.log(y); //returns 523
//Undefined: Any variable that does not have a value is "undefined".
//ex.
var cat; //there is no value assigned here
console.log(cat); //returns undefined
//Null: Null means the value is nothing. You can empty an object
//by assigning it to null.
//ex.
var dog = null;
console.log(dog); //returns null
//NaN: NaN means "Not a Number". This is the result you will get
//when a number is not a legal number. If you try to do arithmetic with
//a word instead of a number you will see "NaN" -Not a Number.
//ex.
var bird = 23 * "robin"; // "robin" is a string and Not a Number
console.log(bird); // returns NaN
var bird = 23 * 2; //both are numbers here
console.log(bird); //returns 46
//Infinity & -Infinity: Infinity is a numeric value that represents
//positive infinity. -Infinity is a numeric value that represents
//negative infinity.
//Infinity is displayed when a number exceeds the upper limit of
//the floating point numbers, which is 1.797693134862315E+308
//-Infinity is displayed when a number exceeds the lower limit of the floating
//point numbers, which is -1.797693134862316E+308.
//Anything you devide by zero will give you infinity/-infinity.
//ex.
var inf = 5 / 0;
console.log(inf); //returns infinity
var inf = -5 / 0;
console.log(inf); // returns -infinity
//
//
//
//
//
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment