Reputation: 2153
console.log("%test"); // %test
console.log("%%test"); // %test
console.log("%%%test"); // %%test
etc
Say I have a string that may or may not have a number of consecutive '%' How can I print it correctly (with all percent characters)?
Example:
var myString = getStringFromAnAPi(); // say, the API returns "ping%%%pong"
console.log(myString) // ping%%pong -> missing one %
Upvotes: 1
Views: 2972
Reputation: 26312
this way you can append text to %,
console.log("%",'test'); // %test
console.log("%%","test"); // %test
console.log("%%%","test"); // %%test
in html,
<div>%test</div>
<div>%%test</div>
<div>%%%test</div>
output
%test
%%test
%%%test
Upvotes: 0
Reputation: 4416
You can do that by: console.log('%s%%%', 'test');
. See JSFiddle: http://jsfiddle.net/8B5Vh/
Upvotes: 2