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.
new String('message') !== 'message'is the big one.2and3. Never. (Well maybe in some cases you would use it but normally you don't and you shouldn't) If you use it and you don't know what you're doing you will get mysterious errors in your code.2and3break things but1does not?2and3behave differently?