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.
Which command-line tool is most commonly used to install Deno on a UNIX-like system?
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.
What is the correct command to execute a TypeScript file named 'hello.ts' using Deno?
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.
When running a script that reads a file in Deno, which flag must be provided to allow this operation?
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.
How would you output 'Hello, Deno!' in a TypeScript file using 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.
What is the purpose of the '--allow-net' flag when running a Deno script?
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.
By default, what level of access does a Deno script have after running 'deno run' without any permission flags?
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.
Which command displays the currently installed Deno version on your system?
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.
Which file extensions does Deno natively support for source files when running scripts?
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.
If a script requires both reading files and accessing the network, what is the correct way to provide both permissions when running it?
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.
Which command should you use to upgrade your existing Deno installation to the latest version?
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.