Created
June 1, 2012 08:55
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** 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