To try it:
Open the Console. For example, press
J(Windows, Linux) or
2 + 2.
The Console immediately displays the result
4on the next line while you type. The
If you press
Autocompletion to write complex expressions
To try it:
- Press the arrow keys to highlight
documenton the dropdown menu.
- Press the
Tabkey to select
- Type another
.to get a large list of possible properties and methods available on the body of the current webpage.
As with many other command-line experiences, you also have a history of commands. Press
Up Arrow to display the commands you entered before. Autocompletion also keeps a history of the commands you previously typed. You can type the first few letters of earlier commands and your previous choices display in a textbox.
Also, the Console also offers quite a few utility methods that make your life easier. For example,
$_ always contains the result of the last expression you ran in the Console.
Enter. The one line limitation may frustrate you. To work around the one line limitation, press
Enter instead of
Enter. In the following example, the value displayed is the result of all the lines run in order.
If you start a multiline statement in the Console, it gets automatically recognized and indented. For example, if you start a block statement with a curly brace.
Network requests using top-level await()
fetch API without wrapping the
await statement with an async function.
To get the last 50 issues that were filed on the Microsoft Edge Developer Tools for Visual Studio Code GitHub repo:
Open the Console.
Copy and paste the following code snippet to get an object that contains 10 entries.
await ( await fetch( 'https://api.github.com/repos/microsoft/vscode-edge-devtools/issues?state=all&per_page=50&page=1' )).json();
The 10 entries are hard to recognize, since a lot of information is displayed. You can use the
console.table() log method to only receive the information in which you're interested.
To reuse the data returned from an expression, you can use the
copy() utility method of the Console. The following code snippet sends the request and copies the data from the response to the clipboard.
copy(await (await fetch( 'https://api.github.com/repos/microsoft/vscode-edge-devtools/issues?state=all&per_page=50&page=1' )).json())