Consider this Deno script that imports the lodash npm package and uses its capitalize function:
import { capitalize } from "npm:lodash";
console.log(capitalize("deno"));What will this code print when run with deno run --allow-net?
import { capitalize } from "npm:lodash"; console.log(capitalize("deno"));
Think about what the capitalize function does to a string.
The capitalize function from lodash converts the first letter of the string to uppercase and the rest to lowercase. So "deno" becomes "Deno".
Which of the following import statements correctly imports the axios npm package in a Deno script?
Deno supports direct npm imports with a special prefix.
Deno allows importing npm packages directly using the npm: prefix. Option D uses this correct syntax. Option D uses a CDN URL which is valid but not the direct npm import feature. Option D uses CommonJS require which Deno does not support natively. Option D tries to import from a local node_modules folder which is not standard in Deno.
Given this Deno script:
import { v4 } from "npm:uuid";
console.log(v4());Running deno run script.ts results in an error: Uncaught ReferenceError: crypto is not defined. What is the most likely cause?
import { v4 } from "npm:uuid"; console.log(v4());
Deno's crypto API is behind a flag in some versions.
The uuid package uses the crypto API to generate random values. In Deno, the crypto API is sometimes behind the --unstable flag. Without it, the script throws a ReferenceError.
result after running this Deno code?Consider this Deno script using the dayjs npm package:
import dayjs from "npm:dayjs";
const result = dayjs("2024-01-01").add(1, "month").format("YYYY-MM-DD");
console.log(result);What will be printed?
import dayjs from "npm:dayjs"; const result = dayjs("2024-01-01").add(1, "month").format("YYYY-MM-DD"); console.log(result);
Adding one month to January 1st should move to February 1st.
The dayjs library adds one calendar month to January 1, 2024, resulting in February 1, 2024. The format outputs it as "2024-02-01".
Choose the correct statement about how Deno handles npm packages:
Think about Deno's security model and how it applies to npm packages.
Deno enforces security permissions for scripts, including those importing npm packages. If an npm package needs network or file system access, the user must grant explicit permissions via flags like --allow-net or --allow-read. Option B is false because some CommonJS packages need manual conversion or shims. Option B is false because Deno caches packages on disk. Option B is false as Deno can support native bindings with proper setup.
