Skip to content

Instantly share code, notes, and snippets.

@nateplusplus
Last active June 11, 2017 16:45
Show Gist options
  • Save nateplusplus/beacaa529589bc8be9e4afddf426ee89 to your computer and use it in GitHub Desktop.
Save nateplusplus/beacaa529589bc8be9e4afddf426ee89 to your computer and use it in GitHub Desktop.
ES2017 Do Expression Example - An example of using do expressions to assign a variable in ES2017! Read more at: https://natehub.blogspot.com/2017/05/the-future-of-javascript-and-beyond.html
// Use do expression when assigning variables
var x = do {
function foo() {
return ...
}
var a = 3
foo(a * 7)
};
// Use do expression with try-catch to capture errors when assigning variables
var x = do {
try { foo( 10 ); }
catch { (err) { err; } }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment