DEV Community

Discussion on: 1. let, const and ... var

Collapse
 
adrianhelvik profile image
Adrian

Oh, no. I only ever use var in this scenario. Lets me skip out of the block scope without a separate variable declaration. And if no error happens, the variable is just undefined.

Thread Thread
 
islam profile image
Islam Sayed

Aha :)
So here is a place where var is still useful 😉

Thread Thread
 
qm3ster profile image
Mihail Malo • Edited

@adrianhelvik
Did you mean:

let error
try {
  await foo()
} catch (e) {
  error = e
}
expect(error.message).toMatch('foo') // you can use string literals if you don't have a complex RegEx