I just noticed the strange behavior of JS that led to an annoying error.
Basically, I'm testing str with a RegExp object (.test () method) in an if statement. For the same line checked, if in my code I only have if, regexp.test () returns true, and it fits perfectly in the if.
The problem is that if I have else (and I need it), for some reason, for the same str check, regexp.test () returns false, and it goes into else ...
What is this behavior?
I have done many tests ...
TL / DR: for the same line tested on the same RegExp, if only the IF statement exists, regexp.test () returns true, but if I have else, it returns false.
some code
I forgot to say that an error does not occur with all words ..
http://jsfiddle.net/zrwkU/13/
Write the word "armoire" in the text box and press enter. This jsfiddle has an "else return false" and nothing happens.
Remove the "else return false" in the searchdeeper function (if (regexp.test (verified)) {) and repeat the test. Now it goes to the if and msgbox popup.
source share