But, when we want to view and edit a piece of code we executed before, we have to use the up arrow key ↑ (just like cycling through terminal history). When we do that, we can't expect the browser to break into a new line when you hit enter inside a loop or a function while editing it.
In Chrome, open dev tools by pressing F12 and navigate to the Sources tab. Under that tab, on the left side, you will see a tab called Snippets, click on that. If you don't see it, click on the double angled brackets button (circled in red below) to expand the menu.
After writing the code, click on the run/play button on the bottom right corner (highlighted in green) or press ctrl + enter, to run it. You can format the code using the button on the bottom left corner (circled in red above). You can view the output in the Console tab.
After writing the code, click on the run button or hit ctrl + enter to run it. You can format the code using the button with curly brackets (circled in red below). The output will be displayed on the right.
We can run the code multiple times in Chrome without any errors. But Firefox gives redeclaration error if we try to run the code multiple times.
To avoid this error, wrap the code in a function and call it or write an IIFE (Immediately Invoked Function Expression)😉
Read more about Chrome's snippets feature here, and about Firefox's multi-line editor mode here.