Deno is a modern runtime for JavaScript and TypeScript. What is its main goal?
Think about what Deno offers beyond just running code.
Deno is designed to run JavaScript and TypeScript securely with built-in tools like a package manager and formatter.
Deno runs scripts with strict permissions. What happens if a script tries to read a file without permission?
const data = await Deno.readTextFile("secret.txt"); console.log(data);
Deno is designed to be secure by default.
Deno requires explicit permission to access files. Without permission, it throws an error to protect the system.
You have a file named app.ts. Which command runs it correctly with Deno?
Deno supports TypeScript natively without compiling first.
Deno can run TypeScript files directly using deno run. No separate compilation is needed.
Consider this script saved as read.ts:
const data = await Deno.readTextFile("info.txt");
console.log(data);Running deno run read.ts causes an error. Why?
Think about Deno's security model and permissions.
Deno requires explicit permission flags like --allow-read to read files. Without it, the script fails.
Given the following script counter.ts:
let count = 0;
function increment() {
count += 1;
return count;
}
console.log(increment());
console.log(increment());
console.log(count);What will be printed when running deno run counter.ts?
Track how the variable count changes after each function call.
The function increments count by 1 each time and returns it. So the outputs are 1, then 2, then the final count is 2.
