简体   繁体   中英

How to run the same snippet multiple times without page reload?

I am playing with JavaScript in "Sources" tab in Google Chrome. I have created this snippet:

const sayHello = () => console.log("Hello");
sayHello();

The problem is - I can run it only one time. If I clicked on "Run" button again - an error will be displayed in "Console":

Uncaught SyntaxError: Identifier 'sayHello' has already been declared at :1:1

Of course I can Refresh the page each time before I ran the Snippet - but it's get tedious and I would much prefer another solution. Basically I want to write multi-line JS code and then execute it and see all its output in console.

Try to use 'var' instead of 'const'.

You cannot rewrite constants, they are read only.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM