Default exports vs named exports
📖 Scenario: You are building a small TypeScript project with two modules. One module will export a function as a default export, and the other module will export multiple functions as named exports. You will learn how to create and use both default and named exports.
🎯 Goal: Create a TypeScript project with one module using a default export and another module using named exports. Then import and use these exports in a main file.
📋 What You'll Learn
Create a module file
greetDefault.ts with a default exported function called greetDefault that returns the string 'Hello from default export!'.Create a module file
greetNamed.ts with two named exported functions called greetMorning and greetEvening that return 'Good morning!' and 'Good evening!' respectively.Create a main file
main.ts that imports the default export from greetDefault.ts and the named exports from greetNamed.ts.Call all three functions in
main.ts and print their returned strings.💡 Why This Matters
🌍 Real World
Modules with default and named exports are common in TypeScript projects to organize code and share functionality between files.
💼 Career
Understanding how to use default and named exports is essential for working on modern TypeScript and JavaScript codebases in professional development.
Progress0 / 4 steps