{"action":"created","issue":{"url":"https://api.github.com/repos/marijnh/Eloquent-JavaScript/issues/273","repository_url":"https://api.github.com/repos/marijnh/Eloquent-JavaScript","labels_url":"https://api.github.com/repos/marijnh/Eloquent-JavaScript/issues/273/labels{/name}","comments_url":"https://api.github.com/repos/marijnh/Eloquent-JavaScript/issues/273/comments","events_url":"https://api.github.com/repos/marijnh/Eloquent-JavaScript/issues/273/events","html_url":"https://github.com/marijnh/Eloquent-JavaScript/issues/273","id":294237505,"number":273,"title":"Unclear section on parameter scope","user":{"login":"chsm","id":2807060,"avatar_url":"https://avatars2.githubusercontent.com/u/2807060?v=4","gravatar_id":"","url":"https://api.github.com/users/chsm","html_url":"https://github.com/chsm","followers_url":"https://api.github.com/users/chsm/followers","following_url":"https://api.github.com/users/chsm/following{/other_user}","gists_url":"https://api.github.com/users/chsm/gists{/gist_id}","starred_url":"https://api.github.com/users/chsm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chsm/subscriptions","organizations_url":"https://api.github.com/users/chsm/orgs","repos_url":"https://api.github.com/users/chsm/repos","events_url":"https://api.github.com/users/chsm/events{/privacy}","received_events_url":"https://api.github.com/users/chsm/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-02-04T22:31:39Z","updated_at":"2018-02-05T09:10:04Z","closed_at":"2018-02-05T09:10:04Z","author_association":"NONE","body":"Hey Marijn,\r\n\r\nHuge fan of EJS - have the 2nd edition in print and have been going through the 3rd edition draft online as well.\r\n\r\nI think the [example](https://eloquentjavascript.net/3rd_edition/03_functions.html#c_C7Va9Kfw9m) given in the Chapter 3 section on parameter scope is a little unclear.\r\n\r\n```javascript\r\nconst halve = function(n) {\r\n  return n / 2;\r\n};\r\n\r\nlet n = 10;\r\nconsole.log(halve(n * 2));\r\n// → 10\r\n```\r\n\r\nThe goal of the section is to clarify that if the same variable name is used both outside a function and also within it, only the innermost scope is used and the function will not recognize the variable as declared without. While the code example obviously demonstrates it, I think it is a little unclear because the result of calling `halve(n)` with `n` as the function parameter happens to give the *same* result we would expect if the function *were* accessing the variable from the global scope...\r\n\r\nPerhaps an example like the following would better demonstrate the point?\r\n\r\n```javascript\r\n\r\nlet x = 2;\r\nlet y = 10;\r\n \r\nconst fraction = function(x, y) {\r\n  let numerator = x; // this reads the *parameters* x and y passed to the function,\r\n  let denominator = y; // not the globally-defined variables outside the function body\r\n  return numerator / denominator;\r\n}\r\n\r\nconsole.log(fraction(3, 10));\r\n// → 0.3 (not 0.2)\r\n```"},"comment":{"url":"https://api.github.com/repos/marijnh/Eloquent-JavaScript/issues/comments/363022895","html_url":"https://github.com/marijnh/Eloquent-JavaScript/issues/273#issuecomment-363022895","issue_url":"https://api.github.com/repos/marijnh/Eloquent-JavaScript/issues/273","id":363022895,"user":{"login":"marijnh","id":144427,"avatar_url":"https://avatars3.githubusercontent.com/u/144427?v=4","gravatar_id":"","url":"https://api.github.com/users/marijnh","html_url":"https://github.com/marijnh","followers_url":"https://api.github.com/users/marijnh/followers","following_url":"https://api.github.com/users/marijnh/following{/other_user}","gists_url":"https://api.github.com/users/marijnh/gists{/gist_id}","starred_url":"https://api.github.com/users/marijnh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marijnh/subscriptions","organizations_url":"https://api.github.com/users/marijnh/orgs","repos_url":"https://api.github.com/users/marijnh/repos","events_url":"https://api.github.com/users/marijnh/events{/privacy}","received_events_url":"https://api.github.com/users/marijnh/received_events","type":"User","site_admin":false},"created_at":"2018-02-05T09:10:04Z","updated_at":"2018-02-05T09:10:04Z","author_association":"OWNER","body":"Attached patch changes the example so that the number 10 doesn't occur twice, which indeed makes it easier to tell the variables/values apart."}}
{"actor":{"display_login":"marijnh"}}