📖 Scenario: You want to create a simple Deno program that prints a greeting message to the console. This is your first step to learning how to run Deno scripts on your computer.
🎯 Goal: Build a basic Deno program that defines a greeting message and prints it to the console.
📋 What You'll Learn
Create a variable with a greeting message
Add a helper variable for the recipient's name
Combine the greeting and name into a full message
Print the full message using Deno's console.log
💡 Why This Matters
🌍 Real World
This project shows how to write and run your first Deno program, which is useful for building server-side scripts and tools with modern JavaScript and TypeScript.
💼 Career
Knowing how to run Deno programs is important for developers working with modern JavaScript runtimes, backend development, and scripting tasks.
Progress0 / 4 steps
1
Create a greeting message variable
Create a variable called greeting and set it to the string "Hello".
Deno
Hint
Use const greeting = "Hello"; to create the variable.
2
Add a recipient name variable
Add a variable called name and set it to the string "World".
Deno
Hint
Use const name = "World"; to add the name variable.
3
Combine greeting and name into a message
Create a variable called message that combines greeting and name with a space between them using a template string.
Deno
Hint
Use backticks and ${} to create the template string.
4
Print the message to the console
Use console.log to print the message variable to the console.
Deno
Hint
Use console.log(message); to print the message.
Practice
(1/5)
1. What command do you use to run a JavaScript or TypeScript file with Deno?
easy
A. node filename.js
B. deno run filename.ts
C. npm start filename.ts
D. deno start filename.js
Solution
Step 1: Understand the Deno run command
Deno uses the command deno run followed by the file name to execute scripts.
Step 2: Identify the correct command for running a file
The correct syntax is deno run filename.ts or deno run filename.js. Other options are for Node.js or incorrect commands.
Final Answer:
deno run filename.ts -> Option B
Quick Check:
Deno runs scripts with 'deno run' [OK]
Hint: Use 'deno run' plus your file name to run scripts [OK]
Common Mistakes:
Using 'node' instead of 'deno run'
Typing 'deno start' which is invalid
Using 'npm start' which is for Node.js projects
2. Which of the following is the correct syntax to print 'Hello, Deno!' to the console in a Deno program?
easy
A. console.print('Hello, Deno!')
B. print('Hello, Deno!')
C. console.log('Hello, Deno!')
D. echo('Hello, Deno!')
Solution
Step 1: Recall JavaScript console output method
In JavaScript and TypeScript, the standard way to print to the console is using console.log().
Step 2: Identify the correct function
Options like print() or echo() are not valid in JavaScript or Deno. console.print() is not a function.
Final Answer:
console.log('Hello, Deno!') -> Option C
Quick Check:
Use console.log() to print text [OK]
Hint: Use console.log() to print messages in Deno [OK]
Common Mistakes:
Using print() which is not defined in JavaScript
Trying console.print() which does not exist
Using echo() which is from shell scripting
3. What will be the output when you run this Deno program?
console.log('Welcome to Deno!');
medium
A. Welcome to Deno!
B. console.log('Welcome to Deno!');
C. SyntaxError
D. No output
Solution
Step 1: Understand console.log behavior
The console.log() function prints the string inside the parentheses to the console.
Step 2: Predict the output
The string 'Welcome to Deno!' will be printed exactly as is, without quotes.
Final Answer:
Welcome to Deno! -> Option A
Quick Check:
console.log prints the string content [OK]
Hint: console.log prints text without quotes [OK]
Common Mistakes:
Expecting the code line itself as output
Thinking it causes a syntax error
Assuming no output without running
4. You wrote this Deno program:
console.log('Hello Deno!')
But when you run deno run hello.ts, you get an error. What is the most likely cause?
medium
A. You must run with 'deno start' instead
B. You need to add a semicolon at the end
C. Deno does not support console.log
D. You forgot to save the file before running
Solution
Step 1: Check common causes of errors when running Deno
If the file is not saved, Deno cannot find the latest code to run, causing errors.
Step 2: Evaluate other options
Semicolons are optional in JavaScript/TypeScript, console.log is supported, and 'deno start' is not a valid command.
Final Answer:
You forgot to save the file before running -> Option D
Quick Check:
Unsaved files cause run errors [OK]
Hint: Always save your file before running with Deno [OK]
Common Mistakes:
Thinking semicolons are mandatory
Believing console.log is unsupported
Using wrong Deno commands like 'deno start'
5. You want to run a Deno program named greet.ts that prints a greeting. Which command will correctly run the program if your terminal is in the same folder as the file?
medium
A. deno run ./greet.ts
B. deno start greet.ts
C. deno run ../greet.ts
D. deno rungreet.ts
Solution
Step 1: Understand file path usage in Deno run
Deno requires the file path to be correct. Using ./greet.ts explicitly points to the current directory.
Step 2: Evaluate other options
deno rungreet.ts is invalid because there's no space after run. deno run ../greet.ts points to the parent directory, which is wrong here. deno start greet.ts is invalid.
Final Answer:
deno run ./greet.ts -> Option A
Quick Check:
Use './filename' to run files in current folder [OK]
Hint: Use './filename' to run files in current directory [OK]
Common Mistakes:
Missing space after 'run' like 'deno rungreet.ts'
Using '../' which points to wrong folder
Trying 'deno start' which is invalid
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.