xia的小窩

一起來coding和碼字吧

0%

從頭開始javascript的學習紀錄-語法-3

這偏著重模組化。

模組初始化

1
2
 #初始化
npm init

點開package.json,加上

1
"type":"moudle",

index.js

1
2
3
let myname = "Rex";

export { myname };

text.js

1
2
3
import { myname } from "./index.js";

console.log(myname); //Rex

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

try……catch……finally

1
2
3
4
5
6
7
8
9
try {
console.log('Hello world');
} catch(err) {
console.log("error");
} finally {
console.log("error");
}
//Hello world
//error