{"action":"closed","issue":{"url":"https://api.github.com/repos/nodeschool/discussions/issues/1237","labels_url":"https://api.github.com/repos/nodeschool/discussions/issues/1237/labels{/name}","comments_url":"https://api.github.com/repos/nodeschool/discussions/issues/1237/comments","events_url":"https://api.github.com/repos/nodeschool/discussions/issues/1237/events","html_url":"https://github.com/nodeschool/discussions/issues/1237","id":89975606,"number":1237,"title":"Decrementing a variable in function parameters","user":{"login":"jimseverino","id":75571,"avatar_url":"https://avatars.githubusercontent.com/u/75571?v=3","gravatar_id":"","url":"https://api.github.com/users/jimseverino","html_url":"https://github.com/jimseverino","followers_url":"https://api.github.com/users/jimseverino/followers","following_url":"https://api.github.com/users/jimseverino/following{/other_user}","gists_url":"https://api.github.com/users/jimseverino/gists{/gist_id}","starred_url":"https://api.github.com/users/jimseverino/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jimseverino/subscriptions","organizations_url":"https://api.github.com/users/jimseverino/orgs","repos_url":"https://api.github.com/users/jimseverino/repos","events_url":"https://api.github.com/users/jimseverino/events{/privacy}","received_events_url":"https://api.github.com/users/jimseverino/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-06-21T23:46:05Z","updated_at":"2015-06-22T01:00:55Z","closed_at":"2015-06-22T01:00:55Z","body":"I'm curious why this works:\r\n\r\n```javascript\r\nfunction repeat(func, num) {\r\n  if (num <= 0) { return 0; }\r\n  func();\r\n  num--;\r\n  repeat(func, num);\r\n}\r\n\r\nrepeat(function foo() {\r\n  console.log('foo ran');\r\n}, 3);\r\n```\r\n\r\nAnd this works:\r\n\r\n```javascript\r\nfunction repeat(func, num) {\r\n  if (num <= 0) { return 0; }\r\n  func();\r\n  repeat(func, num -= 1);\r\n}\r\n\r\nrepeat<...same as before...>\r\n```\r\n\r\nBut this loops endlessly:\r\n\r\n```javascript\r\nfunction repeat(func, num) {\r\n  if (num <= 0) { return 0; }\r\n  func();\r\n  repeat(func, num--);\r\n}\r\n\r\nrepeat<...same as before...>\r\n```\r\n\r\nIt seems like the decrement operator (num--) isn't decrementing num when used as a function parameter. What can explain this?\r\n\r\nThanks in advance for your help.\r\n"}}