This actually isn't the best snippet. See the answers below by [T. J. Crowder](http://meta.stackexchange.com/a/242144/259693) and [canon](http://meta.stackexchange.com/a/242491/259693) for better console simulations.  
There is an important difference though. Mine is a userscript which applies to all posts. The others are for including in a specific snippet, for everyone to benefit from.

----

I've created a script to do this. You can read more about it [here on Stack Apps](http://stackapps.com/q/4931/28683). Download it from [Greasy Fork](https://greasyfork.org/scripts/5479-stack-snippets-console).

See it in action! (Image from [this post](https://meta.stackoverflow.com/a/269875/3187556))

![enter image description here][1]

Update (2014-10-12):  
Now shows errors.


  [1]: https://i.sstatic.net/msg8F.png