How to Use Deno REPL: Interactive JavaScript and TypeScript Console
Use the
deno repl command in your terminal to start the Deno interactive console where you can run JavaScript and TypeScript code line-by-line. It allows quick testing and experimenting without creating files.Syntax
The basic command to start the Deno REPL is deno repl. You can run it in your terminal or command prompt. Once started, you can type JavaScript or TypeScript code directly and see the results immediately.
Optional flags include:
--unstable: Enables unstable Deno APIs.--no-check: Skips type checking for faster startup.
bash
deno repl [--unstable] [--no-check]
Example
This example shows starting the Deno REPL and running simple JavaScript and TypeScript commands interactively.
plaintext
> deno repl Deno 1.36.0 exit using ctrl+d or close() > const greeting: string = "Hello, Deno!"; undefined > greeting "Hello, Deno!" > 5 + 7 12 > function add(a: number, b: number) { ... return a + b; ... } undefined > add(10, 20) 30 > close()
Output
Deno 1.36.0
exit using ctrl+d or close()
undefined
"Hello, Deno!"
12
undefined
30
Common Pitfalls
Some common mistakes when using the Deno REPL include:
- Not exiting properly: Use
ctrl+dorclose()to exit the REPL cleanly. - Expecting persistent state: Variables and functions exist only during the REPL session and reset on restart.
- Using unstable APIs without
--unstableflag: Some features require this flag to work.
plaintext
/* Wrong: Trying to use unstable API without flag */ > Deno.permissions.query({ name: "read" }) // Error: Unstable API /* Right: Start REPL with --unstable flag */ $ deno repl --unstable > Deno.permissions.query({ name: "read" }) Promise { <pending> }
Quick Reference
| Command/Flag | Description |
|---|---|
| deno repl | Start the Deno interactive console |
| --unstable | Enable unstable Deno APIs in REPL |
| --no-check | Skip type checking for faster startup |
| close() | Exit the REPL session |
| ctrl+d | Keyboard shortcut to exit REPL |
Key Takeaways
Start the Deno REPL by running
deno repl in your terminal.Use the REPL to quickly test JavaScript and TypeScript code interactively.
Exit the REPL cleanly with
ctrl+d or close().Use
--unstable flag to access unstable Deno APIs in the REPL.Remember REPL state resets on exit; it does not save variables or functions.