Question: I need to be able to check if a variable exists (if if it doesn't assign it to {}) without throwing an error in javascript. When I try this code

```
if (a) {}    

```

it throws uncaughtReferenceError

What I really want to do is something like this without throwing an error:

```
a = a || {}    

```

or maybe it looks like this

```
if (a) { a = {} }    

```

Answer: 
```
if (typeof a === 'undefined'){
  // variable is not available and you can write a = {}
}

```

but `a = a || {}` is shortly
```
a = a || {}

```

simply won't work, because `a` is not defined. But you can use `typeof` to check if it exists or not.

```
a = (typeof(a) === 'undefined' ? {} : a);

```