Console
Server log
Methods
console.log()
console.log('value');
Value: 1 | true | 'abc' | null | undefined | array | object
console.log('Message'); // String, output Message
console.log([1, 2, 3, 4]); // Array, output: (4)[1, 2, 3, 4]
console.log({a:1, b@2, c:3}); // Object, output {a: 1, b: 2, c: 3}
console.error()
console.error('value'); // For logging error msgs
console.warn()
console.warn('Attention! Allons-y');
console.clear()
console.clear(); // Purpose, Unclear
console.time()
- ms elapsed between console.time('Label') and console.timeEnd('Label') methods execution.
console.time.('Label00');
let funct00 = function(){
console.log('funct00 has begun...');
}
let funct01 = function() {
console.log('funct01 has begun...');
}
funct00();
funct01();
console.timeEnd('Label00');
funct00 has begun...
funct01 has begun...
Label00: 2.015ms
console.table()
console.table({'apples':1, 'bananas':2}); // Input is array or object
(index) Values
a 1
b 2
console.count()
Counts num of times funct() was called
for(let i=0;i<5;i++){
console.count(i);
}
OUtput title="Output"
0: 1
1: 1
2: 1
3: 1
4: 1
console.group()
Group contents in a separate, indented block
console.group('simple');
console.warn('warning!');
console.error('error error error');
console.log('vivi vini vici');
console.groupEnd('simple');
console.log('new section');
simple
warning!
error error error
vivi vini vici
new section
Custom Console Logs
Input is CSS. Log will replace %c
TODO: Not clear what exactly, replacing "%c" does.
const spacing = '10px';
const styles =
`padding: ${spacing}; background-color: white; color: green; font-style:
italic; border: 1px solid black; font-size: 2em;`;
console.log('%cLabel', styles);
- Console sidebar organizes logs
- Msgs can be filtered by label and msg type
Copyright @ 2024 Anne Brown