<p class="title"></p>
<hr>
<p>Name: <span class="name"></span></p>
<hr>
<p>WorkType: <span class="workType"></span></p>
// 全域變數: name
name = 'iWare';

function showName(){
  // 區域變數: workType
  var workType = "Web Design"
  
  //  輸出: iWare Web Design
  $(".title").text(name + " " + workType);
}

showName();

// name為全域變數,在整個程式中都可以被存取
$(".name").text(name);
// workType為宣告在showName function中的區域變數,無法在showName外做存取
$(".workType").text(workType);

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js