At first I was confused about a return value from the javascript RegExp.prototype.test()
method.
Sample code
var reg = new RegExp(/[a-z]/)
var arr = ['test']
console.log(reg.test(arr[1]))
The above code will log out true
to the console when I was expecting a false
value.
Then I realized that undefined
is converted to the string "undefined"
and since the regex matches any lowercase character in the alphabet it returns true
Why does this conversion happen?