Deno Basics: Installation, Permissions, and First Script Quiz Quiz

This quiz covers essential concepts of installing Deno, understanding its permission model, and writing your first script. Test your grasp on basic Deno setup procedures, command-line operations, and security features to build a solid foundation in modern JavaScript runtime environments.

  1. Deno Installation Methods

    Which command-line tool is most commonly used to install Deno on a UNIX-like system?

    1. copy
    2. scp
    3. curl
    4. wget

    Explanation: curl is widely used to download and execute installation scripts for Deno on UNIX-like systems, making the process straightforward. copy is a local command for duplicating files rather than downloading them. scp is for securely copying files between computers and is not typically used for installations. wget can download files but the official installation instructions often prefer curl for piping installation scripts.

  2. Deno Run Command

    What is the correct command to execute a TypeScript file named 'hello.ts' using Deno?

    1. deno run hello.ts
    2. deno open hello.ts
    3. deno start hello.ts
    4. deno execute hello.ts

    Explanation: The deno run command is used to execute JavaScript or TypeScript files in Deno. deno execute, deno start, and deno open are not valid Deno commands for running scripts, and would result in errors.

  3. Understanding Permissions

    When running a script that reads a file in Deno, which flag must be provided to allow this operation?

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

    Explanation: --allow-read grants permission for file read operations within Deno, aligning with its secure-by-default design. --allow-net is for network access, --allow-env allows environment variable access, and --allow-run lets scripts execute subprocesses. Without the correct flag, the operation will fail.

  4. First Output Example

    How would you output 'Hello, Deno!' in a TypeScript file using Deno?

    1. print('Hello, Deno!')
    2. echo('Hello, Deno!')
    3. console.log('Hello, Deno!')
    4. write('Hello, Deno!')

    Explanation: console.log is the standard method for logging messages to the console in TypeScript and JavaScript, which Deno supports. print, echo, and write are not valid global functions in this context and would either cause errors or do nothing.

  5. Network Permission Flag

    What is the purpose of the '--allow-net' flag when running a Deno script?

    1. It enables environment variables
    2. It compiles TypeScript
    3. It allows network access
    4. It grants file system access

    Explanation: --allow-net is specifically used to grant a Deno script access to network resources, such as making HTTP requests. File system access is provided with a different flag (--allow-read or --allow-write), while --allow-env is for environment variables, and compilation happens automatically without a special flag.

  6. Default Security Model

    By default, what level of access does a Deno script have after running 'deno run' without any permission flags?

    1. No file, network, or environment access
    2. Environment variable access only
    3. Full network access
    4. File system access only

    Explanation: Deno scripts, by default, run in a secure sandbox with no access to the file system, network, or environment variables unless explicit permissions are provided. Granting full network access or file system access requires specific flags. Scripts do not receive any sensitive access without user authorization.

  7. Checking Deno Version

    Which command displays the currently installed Deno version on your system?

    1. deno --version
    2. deno --run
    3. deno --check
    4. deno -install

    Explanation: deno --version outputs the installed Deno version, confirming installation status. deno -install is not a standard command, deno --check relates to type checking a script, and deno --run is not a valid command.

  8. Script File Extensions

    Which file extensions does Deno natively support for source files when running scripts?

    1. .ts and .js
    2. .py and .rb
    3. .java and .cpp
    4. .php and .go

    Explanation: Deno natively executes files with the .ts (TypeScript) and .js (JavaScript) extensions. Files like .py, .rb, .java, .cpp, .php, and .go are languages not directly supported by Deno, so attempting to run them would result in errors.

  9. Allowing Multiple Permissions

    If a script requires both reading files and accessing the network, what is the correct way to provide both permissions when running it?

    1. deno run --allow-env script.ts
    2. deno run --allow-read --allow-net script.ts
    3. deno run --allow-exec script.ts
    4. deno run --allow-write script.ts

    Explanation: Specifying both --allow-read and --allow-net together grants the required file and network access. --allow-exec allows creating subprocesses, while --allow-write is for writing files, and --allow-env permits reading environment variables, none of which fulfill both requirements in this scenario.

  10. Updating Deno

    Which command should you use to upgrade your existing Deno installation to the latest version?

    1. deno refresh
    2. deno upgrade
    3. deno install-latest
    4. deno update

    Explanation: deno upgrade downloads and installs the latest version of Deno, ensuring your setup is current. deno install-latest, deno update, and deno refresh are not recognized commands and will produce errors if used.