Deno Interview Prep: Tricky Questions and Real-World Scenarios Quiz Quiz

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.

  1. File Permission Prompt

    If a Deno script tries to read a local file without using the necessary permission flag, what will happen during execution?

    1. A syntax error will occur before execution.
    2. The script will throw a permission error and stop running.
    3. The script will silently skip reading the file.
    4. The file will be read successfully with a warning.

    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.

  2. Module Import Paths

    When importing third-party modules in Deno, which type of module path is primarily used?

    1. A package name from a package registry
    2. A direct URL to the module file
    3. A system environment variable
    4. A relative path without an extension

    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.

  3. TypeScript Support

    How does Deno handle TypeScript files compared to plain JavaScript files during runtime?

    1. TypeScript files require pre-compilation by the user.
    2. Deno automatically compiles TypeScript files before execution.
    3. Deno ignores TypeScript types and runs them as JavaScript directly.
    4. TypeScript files cannot be executed at all.

    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.

  4. Default Network Access

    What happens if a Deno script tries to make an HTTP request without the appropriate permission flag?

    1. A runtime error is thrown, and the request is blocked.
    2. The request proceeds normally without any alerts.
    3. Deno injects a warning but still allows the network call.
    4. The request is queued until permissions are granted.

    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.

  5. Global Variables

    In a Deno program, which global variable provides APIs for timing functions such as setTimeout and setInterval?

    1. document
    2. deno
    3. globalThis
    4. window

    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.

  6. Dependency Caching

    When running a Deno script that imports a remote module for the first time, what does Deno do with that module?

    1. It downloads and caches the module locally for future runs.
    2. It always requires re-downloading on every execution.
    3. It skips downloading and relies entirely on the remote module.
    4. It directly executes the module without caching.

    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.

  7. Script Permissions

    A Deno script needs to read data from the file system and make an HTTP request. Which permission flags should you use?

    1. --allow-read and --allow-net
    2. --allow-net and --allow-write
    3. --allow-read and --allow-env
    4. --allow-env and --allow-run

    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.

  8. Top-Level Await

    Which of the following describes how Deno handles the use of 'await' at the top level of a module?

    1. Deno throws a syntax error if await appears outside functions.
    2. Deno only allows await inside async functions, never at the top level.
    3. Deno fully supports top-level await in modules.
    4. Deno converts top-level await into promises automatically.

    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.

  9. Standard Library Usage

    Which statement is true about using the standard library in a Deno project?

    1. Standard library modules require registration in a config file.
    2. You must import standard library modules via direct URLs.
    3. Standard library modules are included globally and don't need importing.
    4. You can only use standard library features by installing extra plugins.

    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.

  10. Script Execution

    If you run a Deno script called app.ts by typing 'deno run app.ts', which best describes what happens next?

    1. The script asks for permissions after finishing execution.
    2. The script always has full access to the system.
    3. The script is compiled but not executed until permissions are set.
    4. The script runs with no extra permissions except those specified via flags.

    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.