Discover how one simple command can run your code safely and instantly!
Why Running your first Deno program? - Purpose & Use Cases
Imagine you want to run a simple JavaScript file on your computer, but you have to install and configure multiple tools and worry about security settings before it even runs.
Manually setting up environments can be confusing and slow. You might install the wrong versions, face permission errors, or spend hours debugging just to run a tiny script.
Deno lets you run JavaScript and TypeScript programs easily with one tool that handles permissions and dependencies securely and quickly.
node myscript.js // but first install Node, manage packages, and configure environmentdeno run --allow-net myscript.ts // runs script with clear permission control, no extra setupYou can quickly write and run secure scripts without worrying about complex setup or hidden risks.
Running a small web server or API script instantly to test ideas or automate tasks without installing many tools.
Manual setup for running scripts is slow and error-prone.
Deno simplifies running JavaScript/TypeScript with built-in security and tools.
This makes experimenting and building faster and safer.
Practice
Solution
Step 1: Understand the Deno run command
Deno uses the commanddeno runfollowed by the file name to execute scripts.Step 2: Identify the correct command for running a file
The correct syntax isdeno run filename.tsordeno run filename.js. Other options are for Node.js or incorrect commands.Final Answer:
deno run filename.ts -> Option BQuick Check:
Deno runs scripts with 'deno run' [OK]
- Using 'node' instead of 'deno run'
- Typing 'deno start' which is invalid
- Using 'npm start' which is for Node.js projects
Solution
Step 1: Recall JavaScript console output method
In JavaScript and TypeScript, the standard way to print to the console is usingconsole.log().Step 2: Identify the correct function
Options likeprint()orecho()are not valid in JavaScript or Deno.console.print()is not a function.Final Answer:
console.log('Hello, Deno!') -> Option CQuick Check:
Use console.log() to print text [OK]
- Using print() which is not defined in JavaScript
- Trying console.print() which does not exist
- Using echo() which is from shell scripting
console.log('Welcome to Deno!');Solution
Step 1: Understand console.log behavior
Theconsole.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 AQuick Check:
console.log prints the string content [OK]
- Expecting the code line itself as output
- Thinking it causes a syntax error
- Assuming no output without running
console.log('Hello Deno!')But when you run
deno run hello.ts, you get an error. What is the most likely cause?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 DQuick Check:
Unsaved files cause run errors [OK]
- Thinking semicolons are mandatory
- Believing console.log is unsupported
- Using wrong Deno commands like 'deno start'
greet.ts that prints a greeting. Which command will correctly run the program if your terminal is in the same folder as the file?Solution
Step 1: Understand file path usage in Deno run
Deno requires the file path to be correct. Using./greet.tsexplicitly points to the current directory.Step 2: Evaluate other options
deno rungreet.tsis invalid because there's no space afterrun.deno run ../greet.tspoints to the parent directory, which is wrong here.deno start greet.tsis invalid.Final Answer:
deno run ./greet.ts -> Option AQuick Check:
Use './filename' to run files in current folder [OK]
- Missing space after 'run' like 'deno rungreet.ts'
- Using '../' which points to wrong folder
- Trying 'deno start' which is invalid
Ready to prove it?
Pass the test and this pattern moves unknown
