I know this is a stupid question, but I really need help on it. How can I start new line on Chrome console? Every time I hit enter, the console runs my code. How can I start a new line without running the code? Thanks
To create a multi line strings when printing to the JavaScript console, you need to add the new line character represented by the \n symbol. Alternatively, you can also add a new line break using Enter when you use the template literals syntax.
After typing out the first line, instead of hitting enter, hit shift + enter. This will bring you the next line without executing the code. So when you are done, hit enter, it will execute all the code you just wrote.
Also a well known tip, you can bring up JS console in any tabs in the chrome developer tool by hitting ESC (e.g. Elements, Sources etc.).
Another option is to click on 'Sources', click the double arrow button next to 'Page', and click on 'Snippets'. There you can press the '+ New Snippet' button and write your code there.
When you are done writing your code, press Ctrl + Enter and it will run your code and open the console below your code snippet.
This is better for writing multiple lines of code because you can go back and edit your snippet and re-run more easily than re-typing the whole thing in the console.
And if you are using Firefox, they have a similar feature called 'Scratchpad'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With