Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * DATATYPES (SIMPLE & COMPLEX):
- *
- * 0. There are two types of datatypes. The first type is known as "simple" or "primitive." Simple datatypes
- * include: numbers, strings, booleans, NaN, undefined, and null. The reason these datatypes are recognized as
- * simple is because they are atomic, and immutable. Immutable is defined as, "unchanging over time or unable to
- * be changed," meaning these datatypes are fixed and they cannot hold, collect or aggregate other values.
- * Also, since the datatype is fixed, operations on simple values cannot change the initial value: they can
- * only return new simple values.
- * The second datatype is known as "complex" and includes: objects, arrays, and functions. As a literary nerd, I
- * immediately think of "the mutability of man" -- an important theme about human beings and their creations' transience --
- * which acts as the focal point of the poem "Ozymandius" by Percy Shelly. This makes it easy to remember that complex
- * datatypes are changeable: complex datatypes can aggregate other values (allowing complex datatypes to have
- * the potential to be indefinitely large). Complex datatypes are stored as a reference post-assignment of a variable,
- * so they are a copy of the reference of the variable - NOT the literal value.
- */
- //a. Numbers are numeral values:
- var num = 5;
- console.log(num);//This will print 5.
- //b. Strings are a collection of characters between quotes:
- var myFirstName = "Bryan";
- console.log(myFirstName);//This will print Bryan.
- //c. Booleans hold either the value "true" or "false" to handle logic:
- var x = true;
- console.log(x); //This will print true.
- //d. Arrays act as container object. It holds a fixed number of values of a single type:
- var myArray = ["Bryan"];
- var fullName = myArray.push("Patrick","Burnside"); //Here I am using a method to "push" the rest of my name into the array.
- console.log(myArray); //This will print the array with the additional values I pushed into it.
- console.log(fullName); //This will print 3 (the total number of values in the array)
- //e. Objects are a collection of properties. A property is an association between key and its value:
- var person = { //This object stores keys (descriptors) and their relative values.
- name: "Bryan Burnside",
- hair: "Brown",
- eyes: "Brown"
- };
- console.log(person); //This will print the entire object and its contents to the console.
- //f. Functions are a block of code designed to complete a specific task:
- function addTwoNumbers(x,y){
- return x + y; //This function returns the sum of parameter1 and parameter2.
- }
- console.log(addTwoNumbers(5,7)); //This will print 12 to the console.
- //g. NaN is a numeral type that stands for "Not a Number" (it is the returned value of Math problems failing):
- var notNum = Math.sqrt(-1);
- console.log(notNum);//This will print NaN.
- //h. undefined is for undefined values:
- var myUndefinedVar;
- console.log(myUndefinedVar);//This will print undefined.
- //i. null is used to denote the absence of value:
- var nul = null;
- console.log(nul);//This will print null.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement