jsclosure1

by rootjang

HTML

<!DOCTYPE html>
<html lang="ko-KR">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <p>전역 변수 counting</p>
  <button id="inclease">+</button>
  <p id="counter">0</p>
  <script>
    var count = document.getElementById('counter');
    var counter = 0;

    function increase() {
      return ++counter;
    }

    document.getElementById('inclease').onclick = function () {
      count.innerHTML = increase();
    };
  </script>
</body>
</html>