I have this question in mind since I started learning JavaScript last month.
What I have tried?: I researched for it online almost on all good sites but didn't get satisfactory answer in laymans language.
Question: When I create variable let suppose
let name = "mit"
name.toUpperCase()
I am using dot notation to access the method here and I know we use it for something in object. I was confused if the browser creates different object for name variable (which is of string data type here) or what?
String. In Java this would be called boxing."4" - 3resulting in1: the"4"is coerced to a number.name.toUpperCase()it acts as if you've done(new String(name)).toUpperCase(). So, it's as if the string primitive is converted to an object for this one operation, the method is called and then the object is removed. However, the exact implementation might be different - an engine might very well optimise the operation to avoid creating an extra object since if you do that a lot in a loop, you'd create many temporary objects that will need to be garbage collected.