Title: Error about using var · Issue #1 · alhassy/JavaScriptCheatSheet · GitHub
Open Graph Title: Error about using var · Issue #1 · alhassy/JavaScriptCheatSheet
X Title: Error about using var · Issue #1 · alhassy/JavaScriptCheatSheet
Description: In the same way, for the same purpose, we may use var but it has undesirable properties; e.g., its declarations are in the global scope and no error is raised using var x = ⋯ if x is already declared. This is at the end of the Types sect...
Open Graph Description: In the same way, for the same purpose, we may use var but it has undesirable properties; e.g., its declarations are in the global scope and no error is raised using var x = ⋯ if x is already declar...
X Description: In the same way, for the same purpose, we may use var but it has undesirable properties; e.g., its declarations are in the global scope and no error is raised using var x = ⋯ if x is already declar...
Opengraph URL: https://github.com/alhassy/JavaScriptCheatSheet/issues/1
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Error about using var","articleBody":"\u003e In the same way, for the same purpose, we may use `var` but it has undesirable properties; e.g., its declarations are in the global scope and no error is raised using `var x = ⋯` if `x` is already declared.\r\n\r\nThis is at the end of the _Types_ section. First bullet point of three.\r\n\r\nThe part that says _\"its declarations are in the global scope\"_ is incorrect.\r\n\r\nLater, in the _Scope and Statements_ section, you say...\r\n\r\n\u003e`let`, `const` declare local bindings; `var` always makes global ones!\r\n\r\nWhich again is incorrect. You can try this...\r\n\r\n```javascript\r\nfunction f() {\r\n var x = 1;\r\n}\r\nconsole.log(x); // =\u003e Uncaught ReferenceError: x is not defined\r\n```\r\n\r\n...and see that `x` is **not** defined in the global scope. It will be local to the `f` function.\r\n\r\nThe difference about `var` and `let` in what regards scope is:\r\n\r\n- `var` bindings reach either _function scope_ or the _global scope_. `let` bindings can also be limited to _block scope_.\r\n- `var` declarations are hoisted to the start of the scope. `let` bindings are not (*)\r\n\r\n(*) To be more precise they are but have a mechanism that prevents usage before declaration and will throw an error, while `var` won't.","author":{"url":"https://github.com/gezeta-id","@type":"Person","name":"gezeta-id"},"datePublished":"2021-01-27T08:38:20.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/1/JavaScriptCheatSheet/issues/1"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:d0dfc429-f79e-e94b-6c5b-6886d2d8f962 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D31A:16944C:CF7839:118F4A1:698E4682 |
| html-safe-nonce | 30cdc7808481f54d3c06bd1afffb70e4fc8e49f17c303df552ad4125e8ee2722 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMzFBOjE2OTQ0QzpDRjc4Mzk6MTE4RjRBMTo2OThFNDY4MiIsInZpc2l0b3JfaWQiOiI1ODkxMDQ1MzE4OTgwNDIxMjUwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 06071302e704bdeb27ddbb4e7446f27d3e771cb2fae731335b302cbdd3c77180 |
| hovercard-subject-tag | issue:794891063 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/alhassy/JavaScriptCheatSheet/1/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ac0c4fefd9ad18593a02655c4e935b086173fc67aa897ca5eb4057e085072c85/alhassy/JavaScriptCheatSheet/issues/1 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ac0c4fefd9ad18593a02655c4e935b086173fc67aa897ca5eb4057e085072c85/alhassy/JavaScriptCheatSheet/issues/1 |
| og:image:alt | In the same way, for the same purpose, we may use var but it has undesirable properties; e.g., its declarations are in the global scope and no error is raised using var x = ⋯ if x is already declar... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | gezeta-id |
| hostname | github.com |
| expected-hostname | github.com |
| None | a5632af64f7fed7bff1d6a428d1aca1b94fa7a48f760de2d39d9b1effdbf0082 |
| turbo-cache-control | no-preview |
| go-import | github.com/alhassy/JavaScriptCheatSheet git https://github.com/alhassy/JavaScriptCheatSheet.git |
| octolytics-dimension-user_id | 28608756 |
| octolytics-dimension-user_login | alhassy |
| octolytics-dimension-repository_id | 246605253 |
| octolytics-dimension-repository_nwo | alhassy/JavaScriptCheatSheet |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 246605253 |
| octolytics-dimension-repository_network_root_nwo | alhassy/JavaScriptCheatSheet |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 3dda52e29a416820ced574e74040033b820613a2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width