snipt

Ctrl+h for KB shortcuts

Markdown

Assign something to a variable in a console.log() call

Just realized you can do this when debugging JS:

console.log(wat = something);

Then, when debugging in your browser, you'll see the log statement output the something var, and wat will store it. Then you can do methods on wat like you would any normal object, etc.

https://snipt.net/embed/8498b7e2cf4c28f2bc2d77c78d60372b/
/raw/8498b7e2cf4c28f2bc2d77c78d60372b/
8498b7e2cf4c28f2bc2d77c78d60372b
markdown
Markdown
6
2016-12-25T03:56:03
True
False
True
Jun 04, 2012 at 03:16 PM
/api/public/snipt/41660/
assign-something-to-a-variable-in-a-consolelog-call
<p>Just realized you can do this when debugging JS:</p> <pre><code>console.log(wat = something); </code></pre> <p>Then, when debugging in your browser, you'll see the log statement output the <code>something</code> var, and <code>wat</code> will store it. Then you can do methods on <code>wat</code> like you would any normal object, etc.</p>
blog, javascript