-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path02-built-in-constructors.js
92 lines (78 loc) · 1.76 KB
/
02-built-in-constructors.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
/**
* ******************************
* Built In Constructors
* ******************************
**/
/**
* ********************
* String
* ********************
**/
const name1 = 'Jeff'; // primitive value
const name2 = new String('Jeff'); // Object value
//console.log(name1)
//console.log(name2)
name2.foo = 'bar'; // with objects we can add properties
// Where we would run into problems when comparing type - see If Statement:
console.log(typeof name1); // Typeof String
console.log(typeof name2); // Typeof Object
name1 === 'Jeff' ? console.log('YES') : console.log('NO'); // YES
name2 === 'Jeff' ? console.log('YES') : console.log('NO'); // NO
/**
* ********************
* Number
* ********************
**/
const num1 = 5;
const num2 = new Number(5);
console.log(num1);
console.log(name2);
console.log(typeof num1);
console.log(typeof name2);
/**
* ********************
* Boolean
* ********************
**/
const bool1 = true;
const bool2 = new Boolean(true);
console.log(bool1);
console.log(bool2);
console.log(typeof bool1);
console.log(typeof bool2);
/**
* ********************
* Function
* ********************
**/
const getSum1 = function(x, y) {
return x + y;
};
const getSum2 = new Function('x', 'y', 'return 1 + 1');
/**
* ********************
* Object
* ********************
**/
const person1 = { name: 'John' };
const person2 = new Object({ name: 'John' });
console.log(person1);
console.log(person2);
/**
* ********************
* Array
* ********************
**/
const arr1 = [1, 2, 3, 4];
const arr2 = new Array(1, 2, 3, 4);
console.log(arr1);
console.log(arr2);
/**
* ********************
* Regular Expressions
* ********************
**/
const regExp1 = /\w+/;
const regExp2 = new RegExp('\\w+');
console.log(regExp1);
console.log(regExp2);