|
18 | 18 | } |
19 | 19 |
|
20 | 20 | // Regular |
| 21 | + console.log('hello world'); |
21 | 22 |
|
22 | 23 | // Interpolated |
| 24 | + console.log('I am string %s', 'log'); |
| 25 | + console.log('I am int %d', '1.23'); |
| 26 | + console.log('I am object %o' ,{apple: '1kg'}); |
23 | 27 |
|
24 | 28 | // Styled |
| 29 | + console.log('%c This text have the styled that set behind',"color: #00fdff; font-size: 2em;"); |
25 | 30 |
|
26 | 31 | // warning! |
| 32 | + console.warn('This is warnning log'); |
27 | 33 |
|
28 | 34 | // Error :| |
| 35 | + console.error('This is error log'); |
29 | 36 |
|
30 | 37 | // Info |
| 38 | + console.info('This is info log'); |
31 | 39 |
|
32 | 40 | // Testing |
| 41 | + console.assert(1===1,'only show this message when return false'); |
| 42 | + console.assert(1===0,'only show this message when return false 2'); |
| 43 | + |
| 44 | + const p = document.querySelector('p'); |
| 45 | + console.assert(p.innerHTML.match('T'),'can not find this alphabet'); |
33 | 46 |
|
34 | 47 | // clearing |
| 48 | + // console.clear(); |
35 | 49 |
|
36 | 50 | // Viewing DOM Elements |
| 51 | + console.log(p); // html tag |
| 52 | + console.dir(p); // list of attributes |
37 | 53 |
|
38 | 54 | // Grouping together |
| 55 | + dogs.forEach(dog => { |
| 56 | + console.group(); |
| 57 | + // console.groupCollapsed(); |
| 58 | + console.log(`${dog.name}`); |
| 59 | + console.log(`${dog.age}`); |
| 60 | + console.log(`${dog.name} is ${dog.age} years old`); |
| 61 | + console.groupEnd(); |
| 62 | + }); |
| 63 | + |
| 64 | + console.table(dogs); |
| 65 | + console.table(dogs, ["age"]); |
39 | 66 |
|
40 | 67 | // counting |
| 68 | + console.count("sheep"); |
| 69 | + console.count("sheep"); |
| 70 | + console.count("fish"); |
| 71 | + console.count("sheep"); |
| 72 | + console.count("sheep"); |
| 73 | + console.count("fish"); |
| 74 | + console.count("fish"); |
| 75 | + console.count("sheep"); |
41 | 76 |
|
42 | 77 | // timing |
43 | | - |
| 78 | + console.time('fetch my data'); |
| 79 | + fetch("https://api.github.com/users/lchungy90") |
| 80 | + .then(data => data.json()) |
| 81 | + .then(data => { |
| 82 | + console.timeEnd('fetch my data'); |
| 83 | + console.log(data); |
| 84 | + }); |
44 | 85 | </script> |
45 | 86 | </body> |
46 | 87 | </html> |
0 commit comments