I wonder when to use literals and when to use objects to create data type values.
Eg.
When do I use these:
/regexp/
"string"
and when these:
new RegExp("regexp")
new String("string")
Will these give me the same methods and properties?
new RegExp() can be useful when you want to concatenate a value stored in a variable.
var x = "exp";
var regex = new RegExp("reg" + x);
I don't know of any reason not to use String literals, though.
An example of where you may get an unexpected result using a constructor is when creating an Array.
var arr = new Array( 3 ); // creates an Array with an initial length of 3
var arr = new Array( "3" ); // creates an Array with an initial length of
// 1 item that has the value "3"
Overall, I think you'd be safe sticking to literals.
When you attempt to use one of these literals like an object, the literal is converted to an object (a wrapper is applied to it) internally so you access whatever method or property you are trying to use:
var a = /regexp/
a.test(aString);
... is essentially the same as:
var a = new RegExp("regexp");
a.test(aString);
The one difference is that, without eval(), the only way to construct a Regex at runtime is by using RegExp().
Same goes for strings:
var b = "abc";
b.length;
... is the same as:
var b = new String("abc");
b.length;
However, typeof "ABC" is NOT the same as typeof (new String("ABC")). The former returns "string" while the latter returns "object". (see comments).
It's pretty much about preference and readability. Not too many programmers choose new String("ABC");" instead of "ABC", just because while scanning code it's easier to recognize "ABC". This is for the same reason why it's easier to write "ABC": less characters. For Regexes, it is again up to you to decide which to use.
Personally, I use "ABC" for strings (less characters to write, easier to read, more common, etc.)