Challenge your understanding of Deno modules, ES module syntax, and import/export patterns with these fundamental questions. Boost your skills as you identify correct usage, extension rules, and import strategies in Deno's module system.
Which syntax imports the entire default export from a module named 'math.ts'?
Explanation: The first option correctly imports the default export using 'import math from'. The second option incorrectly uses curly braces, which imports named exports. The third option imports all named exports as properties, not just the default. The fourth option with brackets is not valid ES module syntax.
In Deno, which file extension should typically be included when importing a local TypeScript module?
Explanation: Deno expects the exact file extension, so '.ts' must be included for TypeScript files. '.js' is only correct for JavaScript files. Omitting the extension or using '.d.ts' leads to import errors, as Deno does not support extensionless imports by default.
How do you correctly import a named export 'sum' from a module called 'utils.ts'?
Explanation: Curly braces around 'sum' properly import it as a named export. The second option attempts default import which is incorrect if 'sum' is a named export. The third uses a syntax not supported in Deno. The fourth option is not valid syntax.
Which line demonstrates correct syntax for importing a remote module in Deno?
Explanation: Deno allows importing from a remote URL with 'import', so the first option is correct. The second is missing a colon after 'http', making it invalid. The third uses unsupported require syntax. The fourth imports a local file, not a remote one.
If you want to import all exports from a module as a namespace in Deno, which syntax is correct?
Explanation: The first option correctly imports all exports under the 'utils' namespace. The second is only for default exports. The third uses incorrect syntax with curly braces and a star. The fourth does not follow ES module import rules.
Which statement imports a module solely for its side effects without importing any bindings?
Explanation: The correct approach is to use import with only the module path and no bindings. The second option imports a named binding. The third imports all named exports into an object. The fourth option uses require, which is not part of ES modules or Deno.
Which import statement correctly references a sibling file in the same directory named 'config.ts'?
Explanation: Using './' points to the current directory, making the first choice correct. The second omits the dot, which does not look in the current directory. The third references a parent directory. The fourth assumes the root, which is incorrect here.
Which way correctly re-exports a named export 'calculate' from another module in Deno?
Explanation: The first option combines import and export in a way that both imports and re-exports 'calculate'. The second and third are invalid export syntaxes. The fourth uses require, which is not compatible with the ES module style required by Deno.
How do you import both 'add' and 'subtract' named exports from a module called 'operations.ts'?
Explanation: Curly braces with comma-separated names correctly import multiple named exports. The second option tries default and named at once incorrectly. The third's bracket syntax is invalid. The fourth uses require, which is unsupported.
When importing a JSON file named 'data.json' in Deno, what must you ensure for the import to succeed?
Explanation: Deno requires both the file extension and appropriate permissions such as '--allow-read' for importing JSON files. Omitting the extension will cause errors, while require is not supported, and option four is incorrect as Deno does support JSON imports with permission.