Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start a new line in Chrome console window?

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

like image 665
Ashley Avatar asked Aug 18 '17 18:08

Ashley


People also ask

How do you enter a new line in console log?

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.


2 Answers

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.).

like image 119
Achraf Avatar answered Oct 01 '22 20:10

Achraf


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'.

like image 24
mtrussell Avatar answered Oct 01 '22 21:10

mtrussell