forked from scotch-io/javascript-starter-course
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path08-built-in-objects.html
72 lines (63 loc) · 2.17 KB
/
08-built-in-objects.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Getting Started with JavaScript</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<style>
body { padding: 30px; }
</style>
</head>
<body>
<!-- 🔥🔥🔥🔥 start javascript 🔥🔥🔥🔥 -->
<script>
const first = 'this is a string';
const second = String('this is a string');
// console.log('this is a string'.toUpperCase());
// console.log(String('this is a string').toUpperCase());
// console.log(first === second);
console.groupCollapsed('Primitives vs Objects');
console.log(first === second); // true
console.log(
typeof first,
typeof String('this is a string'),
typeof new String()
);
console.groupEnd();
// strings
const sentence = 'this is my sentence';
console.groupCollapsed('String');
console.log(first.toUpperCase()); // THIS IS A STRING
console.log(second.toLowerCase()); // this is a string
console.log(sentence.startsWith('this is')); // true
console.log('🍺'.repeat(20));
console.log('look at me goo '.trim());
console.groupEnd();
// numbers and math
console.groupCollapsed('Numbers and Math');
console.log(1..toString()); // 1
console.log((1).toString()); // 1
console.log(Number.isInteger(5)); // true
console.log(Number.isInteger(5.43)); // false
console.log((1.562342).toFixed(2)); // 1.56
console.log(
Math.random().toFixed(2), // 0.59
Math.ceil(1.56), // 2
Math.floor(6.3) // 6
);
console.groupEnd();
// arrays
const myArr = ['chris', 'nick', 'holly'];
console.group('Arrays');
console.log(myArr.length); // 3
console.log(myArr.join('-')); // chris-nick-holly
console.log(myArr.push('ado'), myArr); // ["chris", "nick", "holly", "ado"]
console.log(myArr.pop(), myArr); // ado ["chris", "nick", "holly"]
// myArr.forEach(function(user) {
// console.log(user);
// });
myArr.forEach((user) => console.log(user));
console.groupEnd();
</script>
</body>
</html>