Looking to get a head start on your next software interview? Pickup a copy of the best book to prepare: Cracking The Coding Interview!
To use the valueOf method in TypeScript, we first need to create a String object. We can do this by using the String constructor or by using a string literal.
let str1: String = new String(“Hello World”);
let str2: String = “Hello World”;
Once we have a String object, we can call the valueOf method to return the primitive value of the string.
console.log(str1.valueOf()); // Output: “Hello World”
console.log(str2.valueOf()); // Output: “Hello World”