Collect output of javascript code

How might I collect, and log, the string value of a JavaScript execution which returns a plaintext value?

For example:

window.location or element.classList, etc -

Thanks in advance!