Reading an article I find the following excerpt:
You can call any of the methods of the string object in a string literal - JavaScript automatically converts the literal string for a temporary string object, calls the method, then discards the temporary string object. You can also use the property String.length with a literal string:
console.log("John's cat".length)
// Irá exibir a quantidade de caracteres na string incluindo o espaço em branco.
// Nesse caso, 10 caracteres.
Correct me if I am wrong, but from what I understand when I define a string literal
it converts the same to a String
temporary object, my doubt is the following, there is difference between doing:
var palavra = 'Palavra'; // String literal
var palavra = String('Palavra'); // String object
When should I use a string literal
or a objeto String
?