/\w+/.test('@asd') // true
/\w+/.test('@') // false
/\w+/.test('asd') // true
Shouldn't the first one return false as well? consider there is a special character inside the string.
I did read thought the doc: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test probably missed something important
The test() method executes a search for a match between a regular expression and a specified string. Returns true or false.
please correct me on which part am i missing here to not getting the expected result.
asdinside the string matches, so no, the match doesn't fail. Your third line is incorrect too,/\w+/.test('asd') // falsegivestrue/^\w+$/.test('@asd')^and$as far as I'm aware. You can write one, but it's not quite as pretty.