Why do we use modules in TypeScript?
Think about how big projects keep code neat and avoid confusion.
Modules help split code into smaller parts that can be reused and prevent variables or functions from clashing with each other.
What will be the output of this TypeScript code using modules?
export const greeting = 'Hello'; import { greeting } from './module'; console.log(greeting);
Imported variables keep their values from the module.
The variable greeting is exported and then imported correctly, so it prints 'Hello'.
What error occurs when trying to import a variable that is not exported from a module?
const secret = 'hidden'; import { secret } from './module'; console.log(secret);
Check if the variable is exported before importing.
If a variable is not exported, TypeScript or the module system will throw an error saying it is not exported.
How do modules help prevent global scope pollution in TypeScript?
Think about how modules isolate code.
Modules create their own scope, so variables inside them donโt affect or conflict with global variables.
Given this module code, how many items will the imported object have?
export const a = 1; export const b = 2; const c = 3; export { c as d };
Count all exported names including renamed exports.
The module exports a, b, and d (which is c renamed), so there are 3 exported items.