Advertisement
Guest User

Untitled

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