Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Something sort of random I just noticed: you can wrap stuff in {} to make blocks without an actual block statement...just a random block of code. That may be pretty useful once the let keyword becomes widely available, and could be used now to maybe organize lots of code?


You can also use blocks this way in C, Java, etc.


However, in C and Java they're actually useful because they delimit variable scope. In JavaScript I'm not aware of any use for them.


EcmaScript is working on growing a way to indicate block scope with "let" as mentioned elsewhere in this thread.


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.


Actually, wrapping the code in {} does make a difference with 'let'. A 'let' in braces does not escape the braces.


Well, the "let" keyword still doesn't work on any major browser so is like it doesn't even exist yet.


"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_JavaScrip...


Yeah, 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: