第一个程序
代码结构如下:
first_code.ts代码如下:
(() => {
function sayHi(str) {
return "hello" + str
}
let text = "zhangsan";
console.log(sayHi(text));
})()
index.html代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<title>React App</title>
</head>
<body>
<script src="./first_code.ts"></script>
</body>
</html>
打开浏览器结果: