samedi 6 février 2021

Regular Expression in Javascript: not true enough for this if-statement? [duplicate]

This is weird... I simply can't figure it out:

var word = "hello";
var re = new RegExp("hello", "g");
alert(re.test(word));
if (re.test(word)) {
  alert("seems to work fine");
} else
  alert("This message is not supposed to pop up, because the if-statement above is (beyond even the slightest of any doubts): " + re.test(word));

Aucun commentaire:

Enregistrer un commentaire