Explore essential Deno concepts, real-world use-cases, and common pitfalls with these practical multiple-choice questions designed for interview preparation. Boost your understanding of Deno’s features, permissions, module system, and typical developer scenarios with this focused quiz.
If a Deno script tries to read a local file without using the necessary permission flag, what will happen during execution?
Explanation: Deno enforces strict security, so accessing files requires explicit permission. Without the correct flag, Deno throws a permission error, halting the process. Reading the file successfully with just a warning is incorrect because Deno never bypasses permissions silently. Skipping the file without notice is not Deno's behavior. Syntax errors are unrelated to runtime permission checks.
When importing third-party modules in Deno, which type of module path is primarily used?
Explanation: Deno favors importing modules directly using URLs, ensuring clear module sourcing and versioning. Relative paths without extensions might work for local files but not for remote third-party code. Using package names from registries and environment variables are practices from other environments, not Deno.
How does Deno handle TypeScript files compared to plain JavaScript files during runtime?
Explanation: Deno includes a built-in TypeScript compiler, converting TypeScript code to JavaScript automatically on-the-fly. Pre-compilation is unnecessary since Deno handles it. Ignoring types and running directly is inaccurate, as compilation still occurs. TypeScript files can absolutely be executed in Deno.
What happens if a Deno script tries to make an HTTP request without the appropriate permission flag?
Explanation: By default, Deno restricts network access for safety. Attempts to make requests without permission cause a runtime error and block the call. Allowing the request, warning only, or queuing the request do not align with Deno's explicit permission policy.
In a Deno program, which global variable provides APIs for timing functions such as setTimeout and setInterval?
Explanation: Deno uses the global variable 'globalThis' to provide access to timing functions and other APIs, offering consistency across environments. 'window' is specific to browsers. 'deno' isn't a global variable but an object with specific APIs. 'document' is also a browser concept.
When running a Deno script that imports a remote module for the first time, what does Deno do with that module?
Explanation: Deno caches remote modules on first download, eliminating the need for repeated downloads and improving performance. Skipping download or requiring re-download every time is inefficient and not Deno's practice. Executing directly without caching is not supported.
A Deno script needs to read data from the file system and make an HTTP request. Which permission flags should you use?
Explanation: --allow-read permits file system reads, and --allow-net enables network access. The other combinations don't provide the right capabilities: --allow-env is for environment variables, --allow-run for subprocesses, and --allow-write for file writes, which are irrelevant here.
Which of the following describes how Deno handles the use of 'await' at the top level of a module?
Explanation: Deno supports top-level await in modules, letting you use asynchronous code without wrapping it in a function. Throwing syntax errors or restricting await only to inside functions is not Deno's behavior. Automatic promise conversion is not necessary, as Deno provides native support.
Which statement is true about using the standard library in a Deno project?
Explanation: Deno requires explicit imports from URLs, including its standard library. The modules aren't available globally by default. Registering modules in configuration files or installing plugins is unnecessary for accessing the standard library.
If you run a Deno script called app.ts by typing 'deno run app.ts', which best describes what happens next?
Explanation: Deno runs scripts with the least privilege by default, granting permissions only through explicit flags. Scripts do not get unrestricted system access by default. Permissions are determined at launch, not after compilation or after script completion.