Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

console.log: if not string, coerce into one

  • Loading branch information...
commit 6b430a95c9a8c965f32d641dced169e6cecd61d6 1 parent 5aadeae
@ry ry authored
Showing with 1 addition and 1 deletion.
  1. +1 −1  src/node.js
2  src/node.js
@@ -194,7 +194,7 @@ process.openStdin = function () {
function format (f) {
var i = 1;
var args = arguments;
- if (!(f instanceof String)) return f;
+ if (!(f instanceof String)) f = String(f);

Just writing
f = String(f);
wouldn’t hurt, because anyway "abc" instanceof String === false

ry added a note

yeah, I was foolishly thinking this would be faster for the string case.

eligrey added a note

f += "" would also work fine, and is a little shorter. I use it in my libraries to convert stuff to strings.

tj added a note


works too

f += "" is good, but I was taught once that it could be confusing for other developers, later.

tj added a note

personally I like String() better, feels more like a cast

@TooTallNate Collaborator

I 2nd (or 3rd, whichever it is) the String()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
return f.replace(/%([sdf])/g, function (x) {
switch (x) {
case '%s': return args[i++];

0 comments on commit 6b430a9

Please sign in to comment.
Something went wrong with that request. Please try again.