-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2_data_types.js
More file actions
89 lines (70 loc) · 1.75 KB
/
2_data_types.js
File metadata and controls
89 lines (70 loc) · 1.75 KB
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
/*
JavaScript 7 basic data types:
1. Number
2. BigInt
3. String
4. Boolean
5. Null
6. Undefined
7. Object and Symbols
*/
/*
Numbers
- they can be used for mathematical operations using arithmetic operators: +, -, /, *.
*/
/*
Number Separator
- use underscore to separate numbers for readability.
*/
let million = 1_000_000;
let billion = 1_000_000_000;
/*
parseInt() and parseFloat()
- it reads and returns the number within the string.
*/
let width = "100px";
let height = "2.5rem";
console.log(parseInt(width));
console.log(parseFloat(height));
/*
String
- a series of characters that are surrounded by quotations.
Types of quotes:
1. single quotes: ''
2. doudble quotes: ""
3. backticks: ``
*/
/*
Strings can represents as an arrays. It also has the length which is the number of characters of that string.
To get the the length of the string, use the length property.
*/
let str = `Hello, World!`;
console.log(str.length);
/*
Characters can be accessed with their indices.
An index starts at 0.
*/
console.log(str[0]);
console.log(str.charAt(8));
console.log(str.at(-1)); // -> square brackets return undefined value when accessing a negative indices, use at() instead or the 4th way.
console.log(str[str.length - 1]);
/*
Boolean
- it uses the keywords true or false to represents boolean literals.
- 0 and 1 can be used to represents booleans, where 0 is false, and 1 is true.
*/
let isVerified = true;
let isPublised = 0;
if (isPublised) {
console.log(`Published? ${true}`)
} else {
console.log(`Published? ${false}`)
}
/*
Null
- it means empty, nothing, non-existend.
*/
/*
Undefined
- it means "a value is not assigned".
*/