Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

scope

index.js

// ch01-before-webpack/02-history-of-js-module/scope/index.js
var outputStr = 'Hello, world!';

設定變數 outputStr

index.html

<!-- ch01-before-webpack/02-history-of-js-module/scope/index.html -->
<!DOCTYPE html>
<html>
  <head>
    <script src="index.js"></script>
  </head>
  <body>
    <script>
      console.log(outputStr);
    </script>
  </body>
</html>

使用 <script>src 引入外部 JavaScript 檔案 index.js ,並在內嵌的 <script> 中使用 index.js 定義的變數 outputStr ,展示 JavaScript 腳本式引入方法的全域特性。