1

If you type manually into chromes console each statement one by one you get an output.

How would I get the same output to the console by debugging code stepping through each of the following:

var foo = 10
foo * 2
foo * 20

without having to do

var foo = 10
console.log(foo * 2)
console.log(foo * 20)

It can be in browser, with browser extension or node.

EDIT 1______ I don't want to use watches either.

SuperUberDuper
  • 9,242
  • 9
  • 39
  • 72
  • This isn't exactly as you are asking for, but you can "watch" a variable by simply console-ing it out after a certain interval as in this example (which uses a library to show the value on the screen): https://github.com/jonbri/ticker-log#execute-ad-hoc-testing-code-with-keyboard-macros – Jonathan.Brink Feb 07 '17 at 17:57
  • You can also use the (non-standard) `object.watch`. See: http://stackoverflow.com/questions/1759987/listening-for-variable-changes-in-javascript-or-jquery – Jonathan.Brink Feb 07 '17 at 17:58
  • What exactly do you need these outputs for? Why doesn't the standard debugger suffice your needs? – Bergi Feb 07 '17 at 22:36

1 Answers1

0

You can't do it automatically.

You can add each expression as a "watch" expression in the Chrome debugger, which will show what the expression evaluates to as your step through the code.

You could create a logger that outputs to console in dev mode and outputs nothing in prod mode. I'm sure there is a good npm package for this already, but, it looks something like this:

var log = env === 'prod' ? function () {} : console.log;

var foo = 10
log(foo * 2);
log(foo * 20);

// dev
>> 20
>> 200
>>

// prod
>>
Matt Mokary
  • 717
  • 6
  • 13