How to compare two regexps?

前端 未结 4 1471
离开以前
离开以前 2021-01-17 10:06

Why do

console.log(/a/ == /a/);

and

var regexp1 = /a/;
var regexp2 = /a/;
console.log(regexp1 == regexp2);

bo

4条回答
  •  遇见更好的自我
    2021-01-17 10:38

    Just a guess - but doesn't JavaScript create a RegExp object for your regex, and therefore because you have created two different objects (even though they have the same "value") they're actually different?

提交回复
热议问题