Last Updated: February 25, 2016
·
1.163K
· gasparotto

Beautiful log in javascript

Simple tip for enhance your javascript console:

String substitution and formatting

%s Formats the value as a string.

%d Formats the value as an integer.

%i Formats the value as an integer too.

%f Formats the object as a floating point value.

%o Formats the value as an expandable DOM element (as in the Elements panel).

%O Formats the value as an expandable JavaScript object.

%c Applies CSS style rules to output string specified by the second parameter.

a real example:

console.log('SENT URL: %c %s >>>>>> %c | HTTP Method: %c"%s" %c| PARAMS: %O', "color: green; font-size: 12px", requestOpts.url, "color: black;", "color: #BA49FF; font-weight: bold; font-size: 12px", requestOpts.method, "color: black;", requestOpts.data);