Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

console.log always evaluates '%d' in a string #1434

Closed
tomdz opened this issue Aug 1, 2011 · 2 comments
Closed

console.log always evaluates '%d' in a string #1434

tomdz opened this issue Aug 1, 2011 · 2 comments

Comments

@tomdz
Copy link

tomdz commented Aug 1, 2011

node
> var sys = require('sys');
> var config = [ "%d" ];
> console.log(sys.inspect(config));
[ 'NaN' ]

node version is 0.4.10 on Ubuntu (Linux nobby 2.6.38-10-generic #46-Ubuntu SMP Tue Jun 28 15:07:17 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux).

@bnoordhuis
Copy link
Member

This hasn't anything to do with JSON, it's a 'feature' of console.log() to support sprintf-style format strings.

> console.log('%d')
NaN
> console.log('%d', 42)
42

We're compatible-ish with how browsers implement it. FF 3.6.18:

>>> console.log('%d')
%d
>>> console.log('%d', 42)
42

Let's fix that.

@koichik
Copy link

koichik commented Aug 7, 2011

@bnoordhuis - Please review.

@koichik koichik closed this as completed in d439c09 Aug 8, 2011
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants