[Javascript] Advanced Console Log Arguments

Get more mileage from your console output by going beyond mere string logging - log entire introspectable objects, log multiple items in one call, and apply C-Style string substitution to make the console work for you.

 

// Can accept multi args
console.log("Hello", "World", "2016"); // Hello World 2016

// Can accept any Javascript type
console.log({foo: "bar", foobar: {bar: "foo"}});

// Substitution
console.log("Hello my name is %s, %d years age, object ->", "Zhentian", 23,  {name: "Zhentian"}); // Hello my name is Zhentian, 23 years age, object -> Object {name: "Zhentian"}

// Styling output
console.log("Listen, this is %cimportant!", "font-size: 24px; color: red"); 

 

 
posted @ 2016-05-14 05:32  Zhentiw  阅读(301)  评论(0编辑  收藏  举报