Basically, my question is about how Javascript handles regex literals.
Contrasting with number, string and boolean where literals are primitive data types and corres
Yes, the following two expressions are equivalent:
var r1 = /ab+c/i,
r2 =new RegExp("ab+c", "i");
The constructor property of both points to the RegExp constructor function:
(/ab+c/i).constructor === RegExp // true
r2.constructor === RegExp // true
And a regexp literal is an instance of RegExp:
/ab+c/i instanceof RegExp // true
The basic difference is that defining regular expressions using the constructor function allows you to build and compile an expression from a string. This can be very useful for constructing complex expressions that will be re-used.