TypeScript Modules and Namespaces Quiz

TypeScript
0 Passed
0% acceptance

A 30-question TypeScript quiz covering ES module imports, exports, module resolution rules, namespaces, namespace merging, ambient modules, and organizational patterns.

30 Questions
~60 minutes
1

Question 1

How does TypeScript determine a file is a module?

A
It contains at least one import or export
B
It has a namespace declaration
C
It uses strict mode
D
It has a .module extension
2

Question 2

Modules provide:

A
File-level scope isolation
B
Automatic global variables
C
Runtime type checking
D
Implicit cross-file sharing
3

Question 3

What does this export?

typescript
export const value = 10;
A
A named export called value
B
A default export
C
A global variable
D
A namespace
4

Question 4

Which is true about modules?

A
They load only what is explicitly imported
B
They expose everything by default
C
They cannot export functions
D
They require namespaces inside them
5

Question 5

What syntax imports the default export?

typescript
// from module 'math'
export default function add(a: number, b: number) {}
A
import add from './math'
B
import { add } from './math'
C
import * as add from './math'
D
import default as add from './math'
6

Question 6

A module can have:

A
Only one default export
B
Multiple default exports
C
Zero named exports
D
Defaults only if using classes
7

Question 7

Which import is correct for a named export?

typescript
export const max = 100;
A
import { max } from './file'
B
import max from './file'
C
import * max from './file'
D
import max as * from './file'
8

Question 8

Wildcard imports create:

A
A namespace-like object containing all exports
B
A default value
C
A tuple of exports
D
A const enum
9

Question 9

Which extension does TypeScript try first when resolving imports?

typescript
import { x } from './utils';
A
./utils.ts
B
./utils.js
C
./utils.json
D
./utils.node
10

Question 10

Module resolution is influenced by:

A
compilerOptions.moduleResolution
B
DOM APIs
C
Node only
D
The README file
11

Question 11

Namespaces are primarily used for:

A
Grouping related types and values internally
B
ES module bundling
C
Async runtime logic
D
Global variable declarations only
12

Question 12

What does this declare?

typescript
namespace Tools {
  export function log(msg: string) {}
}
A
A namespace called Tools containing log
B
A module
C
A default export
D
An enum
13

Question 13

Namespaces differ from modules because namespaces:

A
Do not rely on file boundaries for scoping
B
Are part of ECMAScript
C
Run code at compile time
D
Force default exports
14

Question 14

What happens to these declarations?

typescript
namespace A { export const x = 1; }
namespace A { export const y = 2; }
A
They merge into a single namespace A
B
The second overwrites the first
C
It causes a conflict error
D
They create nested modules
15

Question 15

Namespace merging allows:

A
Incrementally extending namespaces across files
B
Automatic import generation
C
Replacing default exports
D
Creating runtime closures automatically
16

Question 16

What does this declare?

typescript
declare module 'libA' {
  export function run(): void;
}
A
An ambient module definition
B
A runtime module
C
A namespace
D
A class
17

Question 17

Ambient modules are used for:

A
Describing external packages without their own types
B
Running code before imports
C
Creating private fields
D
Bundling CSS
18

Question 18

Modules are preferred over namespaces because:

A
Modules match modern JavaScript standards
B
Modules allow deep merging
C
Modules never require imports
D
Modules are faster
19

Question 19

Namespaces are still useful for:

A
Organizing types within a single file
B
Cross-file runtime packaging
C
Replacing modules
D
Managing network requests
20

Question 20

Why does this import fail?

typescript
import value from './lib';
// lib exports: export const value = 1;
A
Because value is a named export, not a default export
B
Default exports must be strings
C
lib must be an index file
D
import cannot reference files
21

Question 21

Which is valid ES module syntax?

A
export { x } from './file'
B
declare export x
C
using x from './file'
D
require('./file') exports
22

Question 22

What does this create?

typescript
export * from './utils';
A
A re-export of all named exports
B
A default re-export
C
A namespace
D
A const enum
23

Question 23

Namespaces can be nested to:

A
Organize related types hierarchically
B
Replace modules entirely
C
Force runtime encapsulation
D
Automatically generate classes
24

Question 24

Which is true about namespace imports?

A
You must reference exported members through the namespace name
B
Namespaces inject globals
C
Namespaces cannot export values
D
Namespaces auto-import other namespaces
25

Question 25

Which is a recommended approach for application-scale code?

A
Use modules rather than namespaces
B
Use namespaces for all code
C
Avoid using imports
D
Mix modules and namespaces in every file
26

Question 26

Which is a property of modules?

A
They avoid global namespace pollution
B
They create automatic runtime singletons
C
They require namespaces to work
D
They merge automatically
27

Question 27

Namespaces are discouraged in modern applications mainly because:

A
Modules already solve scoping and organization cleanly
B
Namespaces require special compilers
C
Namespaces cannot contain functions
D
Namespaces break JavaScript
28

Question 28

What do modules enforce?

A
Explicit imports for referenced values
B
Global automatic access
C
Automatic merging with other modules
D
Implicit variable hoisting
29

Question 29

Namespace augmentation allows:

A
Adding new members to an existing namespace
B
Merging modules automatically
C
Creating default exports inside namespaces
D
Replacing interfaces with enums
30

Question 30

Overall, modules and namespaces help developers:

A
Organize code, prevent naming conflicts, and clarify visibility
B
Avoid using functions
C
Force deep immutability
D
Remove all compile errors

QUIZZES IN TypeScript