Skip to content

Instantly share code, notes, and snippets.

@getify
Last active January 7, 2024 11:58
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save getify/5285514 to your computer and use it in GitHub Desktop.
Save getify/5285514 to your computer and use it in GitHub Desktop.
since `let (foo = 42) { ... }` is not coming to ES6 after all...

I hereby propose this form of let usage as the next best option, since the clearly better let (foo = 42) { ... } let-block-statement syntax is dead and not coming to ES6:

/*let*/ { let foo = 42;

   // your code that uses `foo`

}

Yes, you need to put a comment on the line, and use the white-space as I've shown, so you get as close to a let-block semantic as possible. Yes, you should use the naked blocks even if you are already using them inside if or for blocks.

Oh, and btw, if you want to use let right now (and not wait for ES6), check out BlockScoper.ify().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment