How to check blank space in JavaScript?

To check blank space in JavaScript, do this: /\s+/g.test(string).

Here's how you do it:

// Prints: "Hello World!" has a space
if (/\s+/g.test('Hello World!')) {
  console.log('"Hello World!" has a space');
}

// Does not print anything
if (/\s+/g.test('HelloWorld!')) {
  console.log('"HelloWorld!" has a space');
}