Bird
Raised Fist0
Denoframework~10 mins

Running your first Deno program - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - Running your first Deno program
Write code in file
↓
Open terminal
↓
Run: deno run filename.ts
↓
Deno compiles and executes
↓
Output shown in terminal
↓
Program ends
This flow shows how you write a Deno program, run it in the terminal, and see the output.
Execution Sample
Deno
console.log("Hello, Deno!");
This code prints 'Hello, Deno!' to the terminal when run with Deno.
Execution Table
StepActionEvaluationResult
1Start program executionN/AProgram begins
2Evaluate console.log statementconsole.log("Hello, Deno!")Prints 'Hello, Deno!' to terminal
3Program endsNo more codeExecution stops
💡 Program ends after printing output because there are no more statements
Variable Tracker
VariableStartAfter Step 2Final
N/AN/AN/AN/A
Key Moments - 2 Insights
Why do I need to open a terminal to run the Deno program?
You run the program using the 'deno run filename.ts' command in the terminal, as shown in the concept flow steps.
What does console.log do in the program?
console.log prints the text inside the quotes to the terminal, which you can see in step 2 of the execution table.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what happens at step 2?
AThe program ends without output
BThe program prints 'Hello, Deno!' to the terminal
CThe program waits for user input
DThe program throws an error
💡 Hint
Check the 'Result' column in step 2 of the execution table
At which step does the program finish running?
AStep 1
BStep 2
CStep 3
DAfter step 3
💡 Hint
Look at the 'Action' and 'Result' columns for step 3 in the execution table
If you change the text inside console.log to 'Hi!', what changes in the execution?
AThe program prints 'Hi!' instead of 'Hello, Deno!'
BThe program crashes
CThe program prints nothing
DThe program waits for input
💡 Hint
Refer to the 'Evaluation' and 'Result' columns in step 2 of the execution table
Concept Snapshot
Write your code in a file (e.g., hello.ts)
Open terminal and run: deno run hello.ts
Deno compiles and runs your code
console.log prints text to terminal
Program ends after last statement
Full Transcript
To run your first Deno program, you write your code in a file with a .ts extension. Then, open your terminal and type 'deno run filename.ts' to start the program. Deno compiles and executes the code. When it reaches console.log, it prints the message to the terminal. After all code runs, the program ends. This simple flow helps you see how Deno runs your code step-by-step.

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

  1. Step 1: Understand the Deno run command

    Deno uses the command deno run followed by the file name to execute scripts.
  2. 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.
  3. Final Answer:

    deno run filename.ts -> Option B
  4. 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

  1. Step 1: Recall JavaScript console output method

    In JavaScript and TypeScript, the standard way to print to the console is using console.log().
  2. Step 2: Identify the correct function

    Options like print() or echo() are not valid in JavaScript or Deno. console.print() is not a function.
  3. Final Answer:

    console.log('Hello, Deno!') -> Option C
  4. 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

  1. Step 1: Understand console.log behavior

    The console.log() function prints the string inside the parentheses to the console.
  2. Step 2: Predict the output

    The string 'Welcome to Deno!' will be printed exactly as is, without quotes.
  3. Final Answer:

    Welcome to Deno! -> Option A
  4. 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

  1. 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.
  2. Step 2: Evaluate other options

    Semicolons are optional in JavaScript/TypeScript, console.log is supported, and 'deno start' is not a valid command.
  3. Final Answer:

    You forgot to save the file before running -> Option D
  4. 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

  1. 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.
  2. 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.
  3. Final Answer:

    deno run ./greet.ts -> Option A
  4. 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 unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard