![ECMAScript Cookbook](https://wfqqreader-1252317822.image.myqcloud.com/cover/58/36700058/b_36700058.jpg)
上QQ阅读APP看书,第一时间看更新
How to do it...
- Create an hello.html file with a some text content:
<html>
<meta charset="UTF-8" />
<head>
</head>
<body>
Open Your Console!
</body>
</html>
- Open hello.html by opening your browser, and entering the following URL: http://localhost:8000/hello.html.
- You should see Open Your Console! displayed by the browser:
![](https://epubservercos.yuewen.com/C944E7/19470395501577006/epubprivate/OEBPS/Images/57a7992c-da30-4b82-8b7a-341c30c4e717.png?sign=1739297218-JcJvyhXRRJtRyJhMH80Txs38FDxfkAUc-0-bd42c1c1a6ad3e992186b71c19935e8d)
- Lets do what the page tells us and open up the Developer Console. For both Firefox and Chrome, the command is the same:
- On Windows and Linux:
Ctrl + Shift + I
- On macOS:
Cmd + Shift + I
- Next, in the same directory, create a file called hello.js, which exports a function named sayHi that writes a message to the console:
// hello.js export function sayHi () { console.log('Hello, World'); }
- Next add a script module tag to the head of hello.html that imports the sayHi method from hello.js (pay attention to the type value).
- Reload the browser window with the Developer Console open and you should see the hello message displayed as text:
![](https://epubservercos.yuewen.com/C944E7/19470395501577006/epubprivate/OEBPS/Images/2e2413b0-c7b4-415e-a8c9-18314f5ee757.png?sign=1739297218-Pu7RUwPEMTpLoNcQJBfluUrRW5DYWmDD-0-3c91d8b842768b3ff589cbb0139859c2)