Javascript: %s or %d represents string?

What you are seeing there is the string substitution patterns that are built into console.log() or console.debug().

The pattern goes as I have presented below:

%s for a String

%d or %i for Number

%f for Floating points

%o for an Object

%j for an JSON

So essentially you are replacing the specifier with the values supplied as so:

var name = 'Chris';
console.log('Hi, my name is %s.', name);
// Hi, my name is Chris.

console.debug('Hi, my name is %s.', name);
// Hi, my name is Chris.

Docs:

  • Docs for Chrome
  • Docs for Firefox
  • Docs for IE
  • Docs for Node.js
  • Docs for Spec

console.log() and console.debug() use printf-style formatting. Below are the officially supported formatters:

Formatter representation:

  • %O Pretty-print an Object on multiple lines.
  • %o Pretty-print an Object all on a single line.
  • %s String.
  • %d Number (both integer and float).
  • %j JSON. Replaced with the string '[Circular]' if the argument contains circular references.
  • %% Single percent sign ('%'). This does not consume an argument.

The results are written in the debug console. just open your command-line or terminal and run it using this:

node debug [script.js | -e "script" | <host>:<port>] command

%c : You can give a style to log text with CSS .

console.log("%c YourText", "color:blue; font-weight:bold;");

You can create multiple style for different console log text.

console.log("%c Text1 %c Text2 %c Text3", "color:red;", "color:green;", "color:blue;");