> For the complete documentation index, see [llms.txt](https://hemantajax-2.gitbook.io/javascript-step-by-step/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hemantajax-2.gitbook.io/javascript-step-by-step/module.md).

# Module

Convenient way of sharing code between files

## Example: Basic Module

Modules are defined with the module keyword, and their exports can be access much like properties of an object

```javascript
module MyModule {
    export function age(n:number){
        return n / 2;
    };

    export var defaultProp = 20;
}
console.log(MyModule.age(32)); // 16
console.log(MyModule.defaultProp); // 20
```

## Sharing Code ( Import and Export Statements )

Modules are a very good way to share code between files

```javascript
// file1.ts
export function third(n : number) : number{return n / 3}
export function half(n : number) : number{return n / 3}

// file2.ts
import calc = require(file1');
calc.half(16); // 8
calc.third(24); // 8
```
