---
# System prepended metadata

title: Better way to write conditions
tags: [JavaScript]

---

# Better way to write conditions

``` javascript
const user = { username: 'Christopher' }
```

## 1
``` javascript
function getuser() {
   if (user) {
      return user
   } else {
      return "No user found"
   }
}
```

## 2
``` javascript
function getuser() {
   if (user) {
      return user
   }
   return "No user found"
}
```

## 3
``` javascript
function getuser() {
   if (!user) {
      return "No user found"
   } 
   return user
}
```

## 4
``` javascript
function getuser() {
   return user ? user : "No user found"
}
```


###### tags: `JavaScript`