|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + <meta charset="UTF-8"> |
| 5 | + <title>Console Tricks!</title> |
| 6 | +</head> |
| 7 | +<body> |
| 8 | + |
| 9 | +<p onClick="makeGreen()">×BREAK×DOWN×</p> |
| 10 | + |
| 11 | +<script> |
| 12 | + const dogs = [ |
| 13 | + { |
| 14 | + name: 'Snickers', |
| 15 | + age: 2 |
| 16 | + }, |
| 17 | + { |
| 18 | + name: 'hugo', |
| 19 | + age: 8 |
| 20 | + }, |
| 21 | + ]; |
| 22 | + |
| 23 | + function makeGreen() { |
| 24 | + const p = document.querySelector( 'p' ); |
| 25 | + |
| 26 | + p.style.color = '#BADA55'; |
| 27 | + p.style.fontSize = '50px'; |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * Firefox doesn't have "Break on...", but it lists event listeners directly in the Inspector. Yay! |
| 32 | + */ |
| 33 | + |
| 34 | + // Regular |
| 35 | + console.log( 'message' ); |
| 36 | + |
| 37 | + // Interpolated |
| 38 | + console.log( 'message with a %s', 'placeholder' ); |
| 39 | + |
| 40 | + // Styled |
| 41 | + console.log( '%cmessage with style', 'color: red; font-size: 24px; font-weight: 600' ); |
| 42 | + |
| 43 | + // warning! |
| 44 | + console.warn( 'warning message' ); |
| 45 | + |
| 46 | + /** |
| 47 | + * Firefox does NOT include a stack trace in warning messages. |
| 48 | + */ |
| 49 | + |
| 50 | + // Error :| |
| 51 | + console.error( 'error message' ); |
| 52 | + |
| 53 | + // Info |
| 54 | + console.info( 'info message' ); |
| 55 | + |
| 56 | + // Testing |
| 57 | + console.assert( false, 'expected false to be true' ); |
| 58 | + |
| 59 | + // clearing |
| 60 | + // console.clear(); |
| 61 | + |
| 62 | + // Viewing DOM Elements |
| 63 | + const p = document.querySelector( 'p' ); |
| 64 | + |
| 65 | + console.log( p ); |
| 66 | + console.dir( p ); |
| 67 | + |
| 68 | + // Grouping together |
| 69 | + dogs.forEach( ( dog ) => { |
| 70 | + console.groupCollapsed( dog.name ); |
| 71 | + console.log( `This is ${dog.name}.` ); |
| 72 | + console.log( `${dog.name} is ${dog.age} years old.` ); |
| 73 | + console.log( `${dog.name} is ${Math.min( 2, dog.age ) * 10.5 + Math.max( 0, dog.age - 2 ) * 4} years old.` ); |
| 74 | + console.groupEnd( dog.name ); |
| 75 | + } ); |
| 76 | + |
| 77 | + /** |
| 78 | + * In Firefox, groups are neither collapsed by default (when using groupCollapsed), nor CAN they even be collapsed! |
| 79 | + */ |
| 80 | + |
| 81 | + // counting |
| 82 | + console.count( 'counter' ); |
| 83 | + console.count( 'counter' ); |
| 84 | + console.count( 'counter' ); |
| 85 | + |
| 86 | + // timing |
| 87 | + console.time( 'fetching' ); |
| 88 | + setTimeout( () => console.timeEnd( 'fetching' ), 1234 ); |
| 89 | + |
| 90 | + // table |
| 91 | + console.table( dogs ); |
| 92 | +</script> |
| 93 | + |
| 94 | +</body> |
| 95 | +</html> |
0 commit comments