0
0
DenoHow-ToBeginner ยท 3 min read

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+d or close() 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 --unstable flag: 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/FlagDescription
deno replStart the Deno interactive console
--unstableEnable unstable Deno APIs in REPL
--no-checkSkip type checking for faster startup
close()Exit the REPL session
ctrl+dKeyboard 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.