Last active
June 11, 2017 16:45
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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