Skip to content

Instantly share code, notes, and snippets.

@lsauer
Created June 1, 2012 08:55
Show Gist options
  • Save lsauer/2850506 to your computer and use it in GitHub Desktop.
Save lsauer/2850506 to your computer and use it in GitHub Desktop.
Javascript: using placeholders %s, %d... in the javascript console and in strings - C++ sprintf-like syntax
/** www.lsauer.com 2011
* http://www.lsauer.com/2011/08/javascript-using-placeholders-s-d-in.html
*/
var r = (r||{
t : "check",
m : "mate",
c: 10.10
});
console.log('It is '+r.t+r.m+' for Player A. Game Stat:'+r.c);
//By using placeholders, the same example statement can be written more clearly, as follows:
console.log('It is %s%s for Player A. Game Stat: %d',r.t, r.m, r.c);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment