---
# System prepended metadata

title: 從頭開始 javascript 的學習紀錄 語法(3)
tags: [JavaScript 學習歷程]

---

# 從頭開始 javascript 的學習紀錄 語法(3)
###### tags: `JavaScript 學習歷程`

* 模組化
```shell=
#初始化
npm init 
```
![](https://i.imgur.com/E1xDfS8.png)

- 點開package.json，加上
```json=
"type":"moudle",
```
- index.js
```javascript=
let myname = "Rex";

export { myname };
```
- text.js
```javascript=
import { myname } from "./index.js";

console.log(myname);   //Rex
```

- p.s也可以用export { ? as ? } 做處理

- try......catch......finally
```javascript=
try {
    console.log('Hello world');
} catch(err) {
    console.log("error");
} finally {
    console.log("error");
}
//Hello world
//error
```
{%hackmd S1DMFioCO %}