Skip to content

Instantly share code, notes, and snippets.

@hiddentribe
Forked from Ncreshon/jsbin.caqabog.js
Created June 11, 2017 00:35
Show Gist options
  • Select an option

  • Save hiddentribe/28a5f56d0accdaf2d302a9d747706999 to your computer and use it in GitHub Desktop.

Select an option

Save hiddentribe/28a5f56d0accdaf2d302a9d747706999 to your computer and use it in GitHub Desktop.
JS Bin[Datatypes (Simple & Complex)]// source https://jsbin.com/caqabog
/* Datatypes (Simple & Complex):
*Datatypes are classified as either simple or complex. Simple datatypes
*include numbers, string, Boolean, NaN, undefined, and null. They are
*immutable they don't hold a value, They return simple values and don't
*change the original value. They only take up a limited amount of space. They are
* stored by value.
*Complex datatypes consist of arrays, objects, and funtions.
*They aggregate other values. They hold an indefinite space od memory. They are
*copied by value.
* Number
*The datatype numbers is just a number. It should not be put in quotations.
* ie 1
*/
console.log(3);
/*
*String
*The datatype string '' or "". Strings can be made up of any characters.
* It can be letters, numbers, punctuation.
*Some characters need to be escaped using a backslash
*to be included in strings. Strings are 0 indexed.
*EXAMPLES
* To include a ' in your string you must escape it using the \'
*/
console.log('I\'m a fan of comics!');//I'm a fan of comics!//
/* Boolean
* Boolean datatype holds either a true or false value.
*It is often used as the result of comparisons. NaN, undefined, 0, -0, '',
*false all rvaluate to a Boolean false.
*/
console.log(3>2);//will return a true value//
/* NaN
* NaN is Not a Number. It is what happens if you try to do math wih a string
*or a calculation fails.
*/
console.log("story" * 6 );
/* Undefined
* Undefined is a default value. T
*/
var example;
console.log(example);
//Null has no value//
/* Array
* Array datatype is a list. An array literal is the []. Arrays can be
*any kind of datatype. Arrays have built in functions called methods
*that are used to manipulate them. Arrays are 0 indexed.
*/
var arr = [1,2,3]
var myArr = arr.concat([4,5]);//concat() is an example of an array method//
console.log(myArr);
console.log(myArr[0]);
/* Objects
*Objects are also known as key/value pairs. Object literal is {}.
* The key and value are seperated by a colon. The key/value pairs are seperated
* by comas.*/
var myKids = { oldestName: "Christian Sky",
babyName: "Harley Quinn", bonusName: "Tymia Nikol", };
console.log(myKids);
/* Like arrays Dot notation or the bracket notation can
* be used to retrive data from objects. */
console.log(myKids.oldestName); //dot notation//
console.log(myKids['babyName']); //bracket notation be sure to use the ''//
/*Functions
*Functions are like instructions encapsalted in a block of code. They are mini programs inside a program
* There are 2 phases to a function 1.) define it 2.) calling it
*The syntax to define a function is */
function name(para,para) {
//body of function//
}
function sum(num1,num2){
var total = num1 + num2
return total;
}
/* When calling a function you would replace the parameters which are place holders
*with the arguments that you want passed thru the function*/
console.log(sum(35,65));
/* Anonymous functions
*Anonymous don't require a function name. Anonymous functions assigned to a
*varible can only be called after the program executes the assignment. On the other
*hand named functions can be accessed anywhere in the program*/
/* Infinity and -Infinity
*Positive infinity (infinity) and negative infinity (-infinity) are
*special value of the number type. The value infinity is greater than any
*other number vice versa for -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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment