3 ms·
Not really, wrapping the code in {} makes no difference whatsoever, but a anonymous function executed after creation does (function(){ /* code */ })() In anoth
by jQueryIsAwesome 15y ago
Not really, wrapping the code in {} makes no difference whatsoever, but a anonymous function executed after creation does (function(){ /* code */ })()
In another note, the article says that '' == false yields false but in Chrome and Firefox it returns true.
- elehack 15y agoActually, wrapping the code in {} does make a difference with 'let'. A 'let' in braces does not escape the braces.
- jQueryIsAwesome 15y agoWell, the "let" keyword still doesn't work on any major browser so is like it doesn't even exist yet.
- bzbarsky 15y ago"let" has worked in Firefox for years; support for it first shipped in Firefox 2 back in 2006. You do have to opt in to it by putting type="application/javascript;version=1.7" on your script tag, since the feature is not backwards-compatible and hence couldn't be added to existing scripts without possibly breaking them. JS 1.7 in general added a bunch of neat features (array comprehensions, destructuring assignment, etc) that are only now slowly making their way to specifications after some foot-dragging by certain parties. See https://developer.mozilla.org/en/JavaScript/New_in_JavaScript/1.7 https://developer.mozilla.org/en/JavaScript/New_in_JavaScrip...
- firefoxman1 15y agoYeah, where right now you must use a self-invoking function, the let keyword would imitate that behavior with just {}'s. Less typing. The only difference is there's no way to return a value from the blocks because this: var name = { return 'Awesome' } ...wouldn't work because, besides return being only for functions, when you use the = it assumes an object literal and throws a syntax error.