-
Notifications
You must be signed in to change notification settings - Fork 129
/
Data Types.js
executable file
·110 lines (86 loc) · 2.05 KB
/
Data Types.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
* Data Types
*
*/
// Number
console.log(10 * 5);
console.log(Math.PI);
console.log(+"10");
console.log(isNaN(1));
// Strings
// Sequences of Unicode characters
console.log("Hello");
console.log("Super duper".length);
console.log("Chris".charAt(4));
console.log("Hello" + " " + "world" + "!");
console.log("i want to be uppercase!!!".toUpperCase());
// Booleans
var shouldBeTrue = true;
var shouldBeNull = null;
if (shouldBeNull === true) {
console.log("This var is true");
}
else {
console.log("This var is not true");
}
// The following evaluates to true
var hasContent = "sfjafdifj";
var myArray = ["asodkasdk", 1, 2, 3, "ada"];
// The following evaluates to false
var doesNotHaveContent = "";
var isZero = 0;
var nonAssignedVariable;
var isFalse = false;
var isNotANumber = NaN;
// Objects
// Collections of name-value pairs
var myOtherObject = {
1: "Chris",
2: "Sally",
3: "Bob",
4: "Billy",
5: "Jane",
};
myOtherObject['unique value'] = "Ashley";
var anotherObject = {
firstName: "Chris",
lastName: "Smith",
age: 50,
numbers: {
mobile: "555-1234",
home: "555-5555",
},
address: "123 Fake St.",
};
var donut1 = {
type: "coconut",
glazed: true,
sweetness: 8,
hasChocolate: false,
sayType: function() {
console.log("Type: " + this.type);
},
showSweetness: function() {
console.log("Sweetness: " + this.sweetness + "/10");
},
};
//Constructor pattern for creating objects
function Donut(type, glazed, sweetness, hasChocolate) {
this.type = type;
this.glazed = glazed;
this.sweetness = sweetness;
this.hasChocolate = hasChocolate;
this.sayType = function() {
console.log("Type: " + this.type);
};
this.showSweetness = function() {
console.log("Sweetness: " + this.sweetness + "/10");
};
}
var coconutDonut = new Donut("coconut", false, 8, true);
var vanillaDonut = new Donut("vanilla", true, 10, false);
// Arrays
// Collection of data
var myNamesArray = ["Chris", "Zack", "Jessica", "John", "Jane"];
var slicedArray = myNamesArray.slice(myNamesArray.length -1);
console.log(slicedArray[0]);