📖 Scenario: You want to quickly try out small pieces of JavaScript or TypeScript code without creating files. Deno REPL lets you do this interactively in your terminal.
🎯 Goal: Learn how to start the Deno REPL, define variables, and run simple commands step-by-step.
📋 What You'll Learn
Start the Deno REPL using the deno command
Create a variable called greeting with the value "Hello, Deno!"
Define a function called sayHello that returns the greeting variable
Call the sayHello function to see the greeting output
💡 Why This Matters
🌍 Real World
Developers often want to test small code snippets quickly without creating files. The Deno REPL provides a fast way to do this interactively.
💼 Career
Knowing how to use the Deno REPL helps developers debug, prototype, and experiment with code efficiently in real-world projects.
Progress0 / 4 steps
1
Start the Deno REPL
Open your terminal and start the Deno REPL by typing deno and pressing Enter. This will open an interactive prompt where you can type JavaScript or TypeScript code.
Deno
Hint
Just type deno in your terminal and press Enter to start the REPL.
2
Create a variable in the REPL
Inside the Deno REPL, create a variable called greeting and set it to the string "Hello, Deno!". Type exactly const greeting = "Hello, Deno!"; and press Enter.
Deno
Hint
Use const greeting = "Hello, Deno!"; to create the variable.
3
Define a function in the REPL
Define a function called sayHello that returns the greeting variable. Type exactly function sayHello() { return greeting; } and press Enter.
Deno
Hint
Use the function keyword and return the greeting variable inside.
4
Call the function to see output
Call the sayHello function by typing sayHello() and pressing Enter. This will display the greeting message in the REPL.
Deno
Hint
Just type sayHello() and press Enter to see the greeting.
Practice
(1/5)
1. What is the main purpose of the deno repl command?
easy
A. To install Deno packages from the internet
B. To start an interactive environment for testing Deno code quickly
C. To compile Deno scripts into executable files
D. To create a new Deno project folder
Solution
Step 1: Understand what REPL means
REPL stands for Read-Eval-Print Loop, an interactive shell to run code instantly.
Step 2: Match REPL purpose with Deno command
The deno repl command opens this interactive shell for Deno code testing.
Final Answer:
To start an interactive environment for testing Deno code quickly -> Option B
Quick Check:
Deno REPL = quick interactive testing [OK]
Hint: REPL means interactive testing shell in Deno [OK]
Common Mistakes:
Confusing REPL with compiling scripts
Thinking REPL installs packages
Assuming REPL creates project folders
2. Which of the following is the correct way to start the Deno REPL in your terminal?
easy
A. deno run repl
B. deno shell
C. deno start repl
D. deno repl
Solution
Step 1: Recall the exact command to start Deno REPL
The official command is deno repl to launch the interactive shell.
Step 2: Check other options for correctness
Options like deno run repl, deno start repl, and deno shell are invalid commands.
Final Answer:
deno repl -> Option D
Quick Check:
Start Deno REPL = deno repl [OK]
Hint: Use exactly 'deno repl' to start the REPL [OK]
Common Mistakes:
Adding extra words like 'run' or 'start'
Using 'deno shell' which is not a Deno command
Confusing with Node.js REPL commands
3. What will be the output when you run the following code inside the Deno REPL?
const x = 5;
const y = 10;
x + y;
medium
A. 15
B. undefined
C. NaN
D. SyntaxError
Solution
Step 1: Evaluate the code line by line in REPL context
Variables x and y are assigned 5 and 10 respectively.
Step 2: Calculate the expression x + y
Adding 5 + 10 results in 15, which REPL will print as output.
Final Answer:
15 -> Option A
Quick Check:
5 + 10 = 15 [OK]
Hint: REPL prints last expression value automatically [OK]
Common Mistakes:
Expecting no output or undefined
Confusing with syntax errors
Thinking variables are not stored in REPL
4. You typed the following in the Deno REPL but got an error:
let a = 10
let b = 20
console.log(a + b)
What is the likely cause of the error?
medium
A. Missing semicolons causing syntax error in REPL
B. Deno REPL does not support console.log
C. Variables must be declared with var, not let
D. You need to run the code in a file, not REPL
Solution
Step 1: Check syntax rules in Deno REPL
Deno REPL requires semicolons or line breaks to separate statements properly.
Step 2: Identify missing semicolons causing error
Missing semicolons after let a = 10 and let b = 20 cause syntax error in REPL.
Final Answer:
Missing semicolons causing syntax error in REPL -> Option A
Quick Check:
Semicolons needed in REPL lines [OK]
Hint: Add semicolons or press Enter twice in REPL [OK]
Common Mistakes:
Assuming console.log is unsupported
Thinking let is invalid in REPL
Believing REPL can't run multi-line code
5. You want to quickly test a function that returns the square of a number in Deno REPL. Which sequence of commands will correctly define and test it?
hard
A.
function square(n) {
return n * n
}
console.log(square(4));
B.
function square(n) {
return n * n
}
square(4)
C.
function square(n) {
return n * n;
}
square(4);
D.
function square(n) {
return n * n;
}
console.log(square(4))
Solution
Step 1: Define the function with proper syntax and semicolons
function square(n) {
return n * n;
}
square(4);
uses semicolons and braces correctly, which is good practice in REPL.
Step 2: Call the function as an expression to see output
Calling square(4); as last line prints 16 automatically in REPL.
Final Answer:
<pre>function square(n) {
return n * n;
}
square(4);</pre> -> Option C
Quick Check:
Function + call + semicolons = correct REPL test [OK]
Hint: End lines with semicolons and call function last [OK]
Common Mistakes:
Omitting semicolons causing REPL errors
Using console.log which prints undefined in REPL
Not calling the function as last expression
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.