6

Both of the lines below, using the console message formatting syntax, are supposed to print "%" to the console twice, and they indeed do in the native developer consoles of Chromium, Firefox and WebKit:

console.log('"%s"', '%');
console.log('%s%%%s', '"', '"');

However, in the Stack Snippets’ console, the first line appears as "%", but the other for some reason displays as "%%%s.

I discovered this while writing an answer demonstrating the very message formatting feature.

Interestingly, this seems to be actually compliant with the WHATWG Console spec (Console LS 2024-10-31 §2.2 “Formatter”), which doesn’t define %% at all – but the spec is pretty incomplete and sparsely maintained, so I think it ought to be considered more of a working draft than a complete specification. (I must say, I hate that “Living Standard” crap.)

(As an amusing aside, Chromium’s implementation is not without its quirks either: console.log('%s%s%s', 'a', '[%s]', 'b', 'c'); prints a[b]c for some reason – but that is not relevant to us.)

0

You must log in to answer this question.

Browse other questions tagged .