Concepts in Focus
Let's see different scenarios that we may come across while exporting.
1. Default Exports
With Default Exports, we can import modules with any name.
1.1 Exporting a variable while defining
We cannot export boolean, number, string, null, undefined, objects, and arrays while defining.
Example:
Output
1.2 Exporting a variable after defining
We can export boolean, number, string, null, undefined, objects, and arrays after defining.
Example:
Output
1.3 Exporting a value or an expression
We can export a value or an expression directly.
Example:
Output
1.4 Exporting a function while defining
We can export a function while defining.
Example:
Output
1.5 Exporting a function after defining
We can export a function after defining.
Example:
Output
1.6 Exporting a class while defining
We can export a class while defining.
Example:
Output
1.7 Exporting a class after defining
We can export a class after defining.
Example:
Output
2. Named Exports
2.1 Exporting multiple variables while defining
We cannot export boolean, number, string, null, undefined, objects, and arrays while defining.
Example:
Output
2.2 Exporting multiple variables after defining
We can export multiple variables after defining.
Example:
Output
2.3 Exporting multiple values and expressions
We can export multiple values and expressions.
Example:
Output
2.4 Exporting multiple functions while defining
We can export multiple functions while defining.
Example:
Output
2.5 Exporting multiple functions after defining
We can export multiple functions after defining.
Example:
Output
2.6 Exporting multiple classes while defining
We can export multiple classes while defining.
Example:
Output
2.7 Exporting multiple classes after defining
We can export multiple classes after defining.
Example:
Output