Last Updated: October 11, 2018
·
14.99K
· diggabyte

JavaScript console.log: native string substitution with %s

Description

String substitution tokens, "%s", can be used in console.log, console.info, console.debug, console.warn and console.error. Simply append an argument for each token present in the message:

Browser Support

  • Firefox (w/ Firebug)
  • Chrome
  • WebKit

Example

console.log("Hello %s", 'world!');
// "Hello world!"

console.log("Hi %s, my name is %s", 'world', 'Joe',);
// "Hi world, my name is Joe."

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside