Search code examples
javascriptfirebug

How to print object as part of a string and have firebug able to inspect it?


right now I use firebug to inspect objects I print occasionally, when I'm getting lazy in my debugging. So if I am in an method and I want to inspect an object I can type:

console.log(object);

and In firebug I can inspect it, including expanding and collapsing keys within it as I feel, it's very covenient.

However, I'd now like to be able to include the object in part of a line. So for instance maybe I want to do something like this:

const value = calculateValue(key);
console.log(`value for ${key} is ${value}`);

This doesn't do what I want. I would get something like:

value for foo is ${object}

instead of value being something that firebug can inspect, expand, etc.

I can work around this with two lines:

console.log('value for key ${key}:');
console.log(value);

which works, but is kind of ugly, and in theory could be a problem if I were trying this while using promises/generators/sagas or any other threading logic.

is there a simple syntax to allow me to provide an object as part of a longer line and have firebug able to recognize it as an object to allow inspection of it?


Solution

  • Use console.dir(object) so it prints to the browser, and it becomes inspectable by Firebug.

    Obviously just use for development and delete from prod.