Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Testing the console's representation of data
var externalObj = {key: 'value'};
var items = {
obj: {
'string prop': 'string val',
5: 10,
nested: [[3, [5, 2]]],
'function': function(){return true;},
reference: externalObj
},
arr: [1, 2, 'hi', 'mom'],
str: 'poppler',
bool: true,
inum: 5,
fnum: 3.14159265,
regex: /[a-zA-Z]{3}[0-9]{2}/g,
func: function(){return false;}
};
for (var item in items) {
console.groupCollapsed(item);
item = items[item];
console.log('------ .toString() ------');
console.log(item.toString());
console.log('------ String() ------');
console.log(String(item));
console.log('------ .log(item) ------');
console.log(item);
console.log('------ .log("string " + item)');
console.log('string' + item);
console.log('------ .log("string", item)');
console.log('string', item);
console.log('------ .log(%s, item)');
console.log('%s', item);
console.log('------ .log(%d, item)');
console.log('%d', item);
console.log('------ .log(%i, item)');
console.log('%i', item);
console.log('------ .log(%f, item)');
console.log('%f', item);
console.log('------ .log(%o, item)');
console.log('%o', item);
console.log('------ .log(%O, item)');
console.log('%O', item);
console.log('------ .dir(item)');
console.dir(item);
console.groupEnd();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.