-
Notifications
You must be signed in to change notification settings - Fork 5
/
01_data_types.js
119 lines (107 loc) · 3.25 KB
/
01_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
111
112
113
114
115
116
117
118
119
/**
* The `dataTypes` function illustrates the variety of data types in JavaScript:
* - Undefined
* - Null
* - Boolean
* - Number
* - BigInt
* - String
* - Symbol
* - Object
* - Function
* - Array
*/
function dataTypes() {
/**
* ========================
* Undefined
* ========================
* An "undefined" type represents a variable that has been declared but not yet
* initialized with a value.
*/
let undefinedVar;
console.log(`Undefined: ${undefinedVar}, typeof: ${typeof undefinedVar}`);
/**
* ========================
* Null
* ========================
* The "null" type signifies the intentional absence of a value.
* Note: typeof null will return 'object', which is a longstanding bug in JavaScript.
*/
let nullVar = null;
console.log(`Null: ${nullVar}, typeof: ${typeof nullVar}`);
/**
* ========================
* Boolean
* ========================
* The "boolean" type has two possible values: true or false.
*/
let bool = true;
console.log(`Boolean: ${bool}, typeof: ${typeof bool}`);
/**
* ========================
* Number
* ========================
* The "number" type can represent both integers and floating-point numbers.
*/
let num = 42;
let float = 42.42;
console.log(`Number: ${num}, typeof: ${typeof num}`);
console.log(`Floating-Point Number: ${float}, typeof: ${typeof float}`);
/**
* ========================
* BigInt
* ========================
* The "BigInt" type can represent integers of arbitrary length.
*/
let bigInt = 42n;
console.log(`BigInt: ${bigInt}, typeof: ${typeof bigInt}`);
/**
* ========================
* String
* ========================
* The "string" type represents textual data.
*/
let str = "Hello";
console.log(`String: ${str}, typeof: ${typeof str}`);
/**
* ========================
* Symbol
* ========================
* The "Symbol" type represents a unique value that's not equal to any other value.
*/
let sym = Symbol("description");
console.log(`Symbol: ${String(sym)}, typeof: ${typeof sym}`);
/**
* ========================
* Object
* ========================
* The "object" type represents a collection of key-value pairs.
*/
let obj = { key: "value" };
console.log(`Object: ${JSON.stringify(obj)}, typeof: ${typeof obj}`);
/**
* ========================
* Function
* ========================
* Functions in JavaScript are objects with the capability of being callable.
*/
function func() {}
console.log(`Function: ${func}, typeof: ${typeof func}`);
/**
* ========================
* Array
* ========================
* Arrays are specialized objects used to store multiple values in a single variable.
*/
let arr = [1, 2, 3];
console.log(`Array: ${arr}, typeof: ${typeof arr}`);
/**
* ========================
* Nuances
* ========================
* Null is a falsy value but it's not the boolean 'false'.
*/
console.log(`Nuances: Null is falsy but not false: ${Boolean(nullVar) === false && nullVar !== false}`);
}
dataTypes();