You might as well guard against both being null:
```javascript
if ( matches ) {
  if ( matches[ 1 ] && matches[ 2 ] ) {
    matchesLang = matches[1].toLowerCase() + matches[2].toUpperCase();
  } else {
    matchesLang = matches[1].toLowerCase();
  }
}
```