In my exploration of TypeScript, I came across the concept that the string primitive type does not have any methods and is simply a value. To utilize methods such as toLowerCase(), one must work with the String type instead.
Curious about this distinction, I decided to experiment:
let s = "Hello";
console.log(typeof(s)); // string
s = s.toLowerCase();
Surprisingly, I found that I could successfully call the toLowerCase method on my string variable. This has left me puzzled – why was this possible?
Furthermore, I am interested in understanding the added value of using String over the string primitive type.
Any insights you can provide would be greatly appreciated.