Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="state retained in outer function scope">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
function countWrapper() {
  var counter = 0;
  console.log(count());    // 1
  console.log(count());    // 2
  console.log(count());    // 3
  function count() {
    counter += 1;
    return counter;
  }
}
countWrapper();
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
jciolekpro
0viewers