Chrome Developer Tools has a feature called “Snippets”. It let’s you store and execute snippets of JS in the context of the current window. This is a good alternative over pasting code directly into the console.
Let’s take the following code as an example:
Click “Execute” (or press
bar is printed in the console.
Now, try to run it again and you’ll get an error:
This is obvious in retrospect. JS does not allow reassigning (nor redeclaring)
The fix is surprisingly easy. Create a scope for your variables. Also, go ahead and set it to strict mode, because you should.
There you go. A Snippet you can execute as many times as you want.