As an option since Chrome 68 (enabled by default since Chrome 72 or perhaps earlier), the DevTools console does as-you-type "eager evaluation" result preview for certain expressions.
For example, if you type in
encodeURIComponent(document.querySelector('.top-bar .-logo').innerHTML);
You get a pink preview of
"%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cspan%20class%3D%22-img%20_glyph%22%3EStack%20Overflow%3C%2Fspan%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20"
below, without hitting Enter.
This does not work, however, for, say
document.querySelector('.top-bar .-logo').href;
and (as would be expected) it doesn't work with expressions that contain loops.
Is it documented somewhere exactly which expressions will work with this and which won't? The initial announcement of the feature mentions
DevTools does not eager evaluate if the expression causes side effects.
but that doesn't seem to explain why it would work for .innerHTML
but not .href
.
What, exactly, determines which expressions it will attempt to evaluate?