Question: What is the best way to check if a single character is a whitespace?

I know how to check this through a regex.

But I am not sure if this is the best way if I only have a single character.

Isn't there a better way (concerning performance) for checking if it's a whitespace?

If I do something like this. I would miss white spaces like tabs I guess?

```
if (ch == ' ') {
    ...
}

```

Answer: 
Based on [this](https://jsbench.me/b1ku0bggvi/1) benchmark, it appears the following method would be most performant:

***For Performance:***

```js
function isWhitespace(c) {
    return c === ' '
        || c === '\n'
        || c === '\t'
        || c === '\r'
        || c === '\f'
        || c === '\v'
        || c === '\u00a0'
        || c === '\u1680'
        || c === '\u2000'
        || c === '\u200a'
        || c === '\u2028'
        || c === '\u2029'
        || c === '\u202f'
        || c === '\u205f'
        || c === '\u3000'
        || c === '\ufeff'
}

```

There are, no doubt, some cases were you might want this level of performance (I'm working on a markdown converter and am trying to squeeze out as much performance as possible). However, in most cases, this level of optimization is unnecessary. In such cases, I would recommend something like this:

***For Simplicity:***

```js
const whitespaceRe = /\s/
function isWhitespace(c) {
  return whitespaceRe.test(c)
}

```

This is more readable, and less likely to have a typo and, therefore, less likely to have a bug.
```
function hasWhiteSpace(s) {
  return /\s/g.test(s);
}

```

This will work

or 
you can also use this indexOf():

```
function hasWhiteSpace(s) {
  return s.indexOf(' ') >= 0;
}

```