How to start a new line in Chrome console window?

25,686

Solution 1

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

Solution 2

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

Solution 3

You can hit Shift + Enter if you are using Windows. If you are on a Mac you can use Ctrl + Return.

For more keyboard shortcuts

Solution 4

Just wanted to add an after thought... The shift + Enter is how you go to a new line without running the code, but I have noticed when I am writing a function and hit shift + enter after my first curly brace, it was giving me an error. So, I find that if you want to go to a new line after your first curly brace, hit enter, it will bring you to the next line with out running it, and from there, use the shift + enter if you want to start a new line. Then enter to run it.

Share:
25,686
Ashley
Author by

Ashley

Updated on December 05, 2021

Comments

  • Ashley
    Ashley over 2 years

    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