代码示例:(标识:eg_js_function_scope_1)
<!DOCTYPE html>
<html>
<body>

<p>函数可以访问函数内定义的变量:</p>

<button type="button" onclick="myFunction()">单击这里!</button>

<p id="demo"></p>

<script>
function myFunction() {
  var a = 4;
  document.getElementById("demo").innerHTML = a * a;
} 

</script>

</body>
</html>
运行结果: