var containsWhitespace = function(str){ return /s/g.test(s); }; console.log(containsSpaces("foo bar"));//Returns true console.log(containsSpaces("foobar"));//Returns false