Timeline for answer to What is the difference between "let" and "var"? by ThinkingStiff
Current License: CC BY-SA 4.0
Post Revisions
78 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Dec 27, 2023 at 21:03 | comment | added | Ethan |
@averageJeo You can also create a block scope by just using {}. Anything inside curly brackets are automatically scoped.
|
|
| Sep 18, 2023 at 16:43 | history | edited | VLAZ | CC BY-SA 4.0 |
clarified global scoping for let (it IS global scoped); clarified hoisting and initialisation steps; unified the hoisting code examples
|
| Aug 4, 2022 at 7:06 | comment | added | S. Dre | JetBrains (at least PHPStorm) typically recommends let in it's IDE help. | |
| Nov 8, 2021 at 12:11 | history | edited | Nimantha | CC BY-SA 4.0 |
Changed "stackoverflow" to "Stack Overflow"
|
| S Oct 25, 2021 at 13:09 | history | suggested | Jody Frankowski | CC BY-SA 4.0 |
Make a proper sentence
|
| Oct 25, 2021 at 12:41 | review | Suggested edits | |||
| S Oct 25, 2021 at 13:09 | |||||
| Aug 9, 2021 at 17:38 | history | edited | Yashwardhan Pauranik | CC BY-SA 4.0 |
added 5 characters in body
|
| Jul 13, 2021 at 5:26 | review | Suggested edits | |||
| Jul 14, 2021 at 6:28 | |||||
| Jun 24, 2021 at 11:27 | history | edited | Sileo | CC BY-SA 4.0 |
Moved the JS code examples into snippets
|
| Apr 26, 2021 at 2:18 | history | edited | JakeMc | CC BY-SA 4.0 |
corrected some comments to clarify the output and actual results
|
| Feb 13, 2021 at 4:48 | history | edited | user128511 | CC BY-SA 4.0 |
added 11 characters in body
|
| Nov 16, 2020 at 23:23 | history | edited | Lanki | CC BY-SA 4.0 |
Added comments
|
| May 7, 2020 at 8:17 | review | Suggested edits | |||
| May 7, 2020 at 10:14 | |||||
| Apr 29, 2020 at 13:14 | history | edited | DDiamond | CC BY-SA 4.0 |
added link for hoisted and fixed definition, the code is not 'moved' to the top of the function: https://dev.to/godcrampy/the-secret-of-hoisting-in-javascript-egi
|
| Feb 27, 2020 at 0:56 | review | Suggested edits | |||
| Feb 27, 2020 at 4:38 | |||||
| Jan 13, 2020 at 15:53 | history | edited | Shay Yzhakov | CC BY-SA 4.0 |
added 2 characters in body
|
| Nov 13, 2019 at 16:57 | history | edited | Luke Girvin | CC BY-SA 4.0 |
added 2 characters in body
|
| Sep 17, 2019 at 7:30 | review | Suggested edits | |||
| Sep 17, 2019 at 8:12 | |||||
| S Sep 14, 2019 at 12:12 | history | suggested | Fazy Fy | CC BY-SA 4.0 |
delete 2 duplicate words
|
| Sep 14, 2019 at 9:59 | review | Suggested edits | |||
| S Sep 14, 2019 at 12:12 | |||||
| S Sep 13, 2019 at 7:53 | history | suggested | user10905710 | CC BY-SA 4.0 |
corrected spelling+ misstake with qoutes
|
| Sep 13, 2019 at 7:33 | review | Suggested edits | |||
| S Sep 13, 2019 at 7:53 | |||||
| Sep 11, 2019 at 13:14 | history | edited | snnsnn | CC BY-SA 4.0 |
Clear wording with proper js terminology, unified style and syntax for the examples
|
| Sep 11, 2019 at 11:36 | comment | added | snnsnn | I think "immediate" would be better term than nearest in "nearest function block". | |
| Jun 24, 2019 at 2:46 | history | edited | Jack Bashford | CC BY-SA 4.0 |
deleted 177 characters in body
|
| Apr 23, 2018 at 2:29 | comment | added | Tim Hong | I would like to correct that let me = 'go' is not truly under global scope like var me = 'go' if you try this.me with let, you will get undefined. If you try this.me with var, you will get me's value, in this case 'go'. | |
| Feb 5, 2018 at 10:22 | history | edited | Matt | CC BY-SA 3.0 |
fixed typo in snippet
|
| Jan 30, 2018 at 17:36 | review | Suggested edits | |||
| Jan 30, 2018 at 18:46 | |||||
| Jul 28, 2017 at 12:01 | history | edited | MegaMatt | CC BY-SA 3.0 |
Rewording for readability
|
| Jun 1, 2017 at 1:08 | comment | added | RBT |
I'm observing that redeclaration behavior remains same even without 'use strict'; mode. So it seems redeclaring a variable with same name using let keyword will always result in error no matter whether we are using strict mode or not. I'm using chrome version 58.
|
|
| May 22, 2017 at 1:27 | comment | added | mormegil |
This answer does not address part of the question: "When should let be used over var?". I've attempted to answer that along with collecting a lot of the useful material in other answers below. If some kind soul is willing to see this put into the community wiki, I will not object to copy-paste in whole or in part.
|
|
| May 8, 2017 at 7:29 | comment | added | Chajnik-U | Unfortunately browsers still (as of May 2017) do not optimize all corner cases for this nice feature and there are possible some loop slowdowns due to that stackoverflow.com/questions/43153889/… | |
| Dec 31, 2016 at 10:24 | history | edited | jfriend00 | CC BY-SA 3.0 |
added 84 characters in body
|
| Nov 24, 2016 at 7:38 | history | edited | Cerbrus | CC BY-SA 3.0 |
Expanding answers: Fixing examples that were rolled back, removing deprecated content.
|
| Nov 24, 2016 at 0:05 | history | rollback | Robert Harvey |
Rollback to Revision 23
|
|
| Nov 23, 2016 at 23:56 | history | edited | Michał Perłakowski | CC BY-SA 3.0 |
added 1211 characters in body
|
| Nov 23, 2016 at 23:42 | history | made wiki | Post Made Community Wiki by Robert Harvey | ||
| Nov 5, 2016 at 12:05 | review | Suggested edits | |||
| Nov 5, 2016 at 13:04 | |||||
| Oct 21, 2016 at 20:40 | history | edited | ThinkingStiff | CC BY-SA 3.0 |
deleted 5 characters in body
|
| Oct 19, 2016 at 17:27 | history | edited | ThinkingStiff | CC BY-SA 3.0 |
added 14 characters in body
|
| Sep 26, 2016 at 3:22 | history | edited | ThinkingStiff | CC BY-SA 3.0 |
deleted 91 characters in body
|
| S Aug 24, 2016 at 8:10 | history | suggested | PaulH | CC BY-SA 3.0 |
Document support changed since 2012
|
| Aug 24, 2016 at 6:46 | review | Suggested edits | |||
| S Aug 24, 2016 at 8:10 | |||||
| Aug 3, 2016 at 21:15 | history | edited | basickarl | CC BY-SA 3.0 |
Removed incorrect semicolon ;)
|
| Jul 19, 2016 at 22:31 | history | rollback | ThinkingStiff |
Rollback to Revision 17
|
|
| S Jul 14, 2016 at 12:15 | history | suggested | Jesús Fuentes | CC BY-SA 3.0 |
Global ain't defined in 'let'
|
| Jul 14, 2016 at 11:28 | review | Suggested edits | |||
| S Jul 14, 2016 at 12:15 | |||||
| Jun 17, 2016 at 13:43 | review | Suggested edits | |||
| Jun 17, 2016 at 14:32 | |||||
| Apr 28, 2016 at 19:12 | history | rollback | ThinkingStiff |
Rollback to Revision 15
|
|
| Apr 26, 2016 at 20:58 | history | edited | BlueRaja - Danny Pflughoeft | CC BY-SA 3.0 |
If it's deprecated, just remove it from the answer.
|
| Apr 22, 2016 at 16:04 | review | Suggested edits | |||
| Apr 22, 2016 at 17:14 | |||||
| Apr 7, 2016 at 20:26 | history | edited | ThinkingStiff | CC BY-SA 3.0 |
deleted 90 characters in body
|
| Apr 7, 2016 at 18:42 | history | edited | ThinkingStiff | CC BY-SA 3.0 |
added 20 characters in body
|
| Apr 7, 2016 at 18:38 | history | rollback | ThinkingStiff |
Rollback to Revision 11
|
|
| Apr 1, 2016 at 20:53 | history | edited | user1114 | CC BY-SA 3.0 |
adding explanation of difference in global variable storage (see http://stackoverflow.com/q/36343969/1114) and removed section of let blocks since support has now been dropped form ALL browsers and the spec
|
| Feb 13, 2016 at 1:42 | history | rollback | ThinkingStiff |
Rollback to Revision 9
|
|
| S Feb 11, 2016 at 18:14 | history | suggested | Richard | CC BY-SA 3.0 |
added redeclaration in same scope
|
| Feb 11, 2016 at 16:39 | review | Suggested edits | |||
| S Feb 11, 2016 at 18:14 | |||||
| Oct 22, 2015 at 22:32 | comment | added | Toothbrush |
Note: As @EricB said, you can use let a = 1; { let a = 2; console.log(a === 2) } console.log(a === 1) in the place of let a = 1; let (a = 2) { console.log(a === 2) } console.log(a === 1). It does exactly the same.
|
|
| May 7, 2015 at 14:16 | comment | added | Eric Bishard |
Just found this repo that allows you to use let blocks in your code. Because let blocks are pretty nice IMHO. github.com/getify/let-er which Transpiles non-ES6 let-blocks into ES6 (or ES3)
|
|
| May 7, 2015 at 14:12 | comment | added | Eric Bishard |
Although a let enclosing block is deprecated you can do the same thing by creating an explicit block with braces. { let bar = foo; let foo = bar; code; more code; console.log(bar + foo); } and simply have your lets at the top of your block of code wrapped in braces.
|
|
| Dec 18, 2014 at 18:44 | history | edited | ThinkingStiff | CC BY-SA 3.0 |
added 15 characters in body
|
| Dec 18, 2014 at 18:44 | history | rollback | ThinkingStiff |
Rollback to Revision 6
|
|
| Dec 17, 2014 at 14:51 | comment | added | Gajus |
let block expression let (variable declaration) statement is non-standard and will be removed in future, bugzilla.mozilla.org/show_bug.cgi?id=1023609.
|
|
| Dec 17, 2014 at 14:50 | history | edited | Gajus | CC BY-SA 3.0 |
let block expression is not standard and will be removed, https://bugzilla.mozilla.org/show_bug.cgi?id=1023609
|
| Sep 26, 2014 at 3:28 | review | Suggested edits | |||
| Sep 26, 2014 at 3:59 | |||||
| Sep 26, 2014 at 3:19 | comment | added | Anvesh Checka | let is not hoisted like its counterpart 'var' Hoisting behaves differently around a function block and any other block | |
| S Mar 22, 2014 at 7:37 | history | suggested | user | CC BY-SA 3.0 |
fixed minor mistake
|
| Mar 22, 2014 at 7:33 | review | Suggested edits | |||
| S Mar 22, 2014 at 7:37 | |||||
| Jan 22, 2014 at 8:16 | vote | accept | TM. | ||
| Jun 7, 2013 at 15:02 | comment | added | batman | @NoBugs, Yes, and it is encouraged that variables are existent only where they are needed. | |
| Jun 7, 2013 at 5:18 | comment | added | NoBugs | So is the purpose of let statements only to free up memory when not needed in a certain block? | |
| Dec 14, 2012 at 10:14 | comment | added | average Joe | Remember you can create block whenever you want. function() { code;{ let inBlock = 5; } code; }; | |
| Sep 1, 2012 at 23:19 | history | edited | ThinkingStiff | CC BY-SA 3.0 |
added 144 characters in body
|
| Aug 3, 2012 at 3:40 | history | edited | ThinkingStiff | CC BY-SA 3.0 |
added 150 characters in body
|
| Jul 13, 2012 at 20:05 | history | edited | ThinkingStiff | CC BY-SA 3.0 |
added 36 characters in body
|
| Jul 12, 2012 at 3:00 | history | edited | ThinkingStiff | CC BY-SA 3.0 |
added 1 characters in body; added 12 characters in body
|
| Jul 12, 2012 at 2:53 | history | answered | ThinkingStiff | CC BY-SA 3.0 |