Difference between the javascript String Type and String Object? does not include case 2.
All of these expressions seem to do mostly the same thing. How are they different?
'message'
String('message');
new String('message');
Difference between the javascript String Type and String Object? does not include case 2.
All of these expressions seem to do mostly the same thing. How are they different?
'message'
String('message');
new String('message');
Basically 'message'
is just a string litrel. You can just use String
functions on that.
What I know that String('message')
& 'message'
are same.
But on new String()
create a new Object of type String
. So you will be able to define your properties
& methods
on it.
Like bellow
var msg = new String('message');
msg.sender = "Someone".
msg.sender //returns "Someone"
var msg = String('message');
msg.sender = "Someone".
msg.sender //returns undefined
var msg = 'message';
msg.sender = "Someone".
msg.sender //returns undefined
But you can't do sane on litrels.