Question: I have the following `try/catch`:

```
try {
    var { app } = require('electron').remote;
} catch (e) {
    var { app } = require('electron');
}

```

Even though it is valid, ESLint is having an issue that says `app` has already been declared.

So, I try and move the var above the `try/catch` and there is an error with the `=` saying that it is an `Unexpected token` like so:

```
var app;
try {
    { app } = require('electron').remote;
} catch (e) {
    { app } = require('electron');
}

```

What is the proper way to do this so ESLint doesn't complain?

Answer: 
First off, since you're clearly using ES2015+ (aka "ES6+"), look at using `let` or `const` rather than `var`. There's basically no use for `var` in an ES2015+ world. (But both of the below will work with `var` as well.)

The parsing problem is because `{` looks like the beginning of a block. You can wrap the entire assignment in `()` to get around that:

```
let app;
try {
    ({ app } = require('electron').remote);
} catch (e) {
    ({ app } = require('electron'));
}

```

Example (faking `require`):

```js
// fake require
function require(name) {
  return {app: {name: "I'm the app"}};
}

let app;
try {
  ({ app } = require('electon').remote);
} catch (e) {
  ({ app } = require('electron'));
}
console.log(app);
```

Or just don't use destructuring at all:

```
let app;
try {
    app = require('electron').remote.app;
} catch (e) {
    app = require('electron').app;
}

```

```js
// fake require
function require(name) {
  return {app: {name: "I'm the app"}};
}

let app;
try {
  app = require('electron').remote.app;
} catch (e) {
  app = require('electron').app;
}
console.log(app);
```
`var` declares a value in the scope of the current function. A `try` statement does not create that kind of scope, so you're re-declaring `app` in your initial code. That's why it doesn't pass linting.

You can use `let` instead of `var`, if `app` is only needed within `try` or `catch` blocks.