Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
107
rated 0 times [  108] [ 1]  / answers: 1 / hits: 55217  / 11 Years ago, tue, may 28, 2013, 12:00:00

In JavaScript, I can declare a string in the following ways;



var a = Hello World;
var b = new String(Hello World);


but a is not an instance of String...



console.log(a instanceof String); //false;
console.log(b instanceof String); //true;


So how do you find the type or instanceof a string literal?



Can JavaScript be forced to create a new String() for every string literal?


More From » string

 Answers
69

use typeof foo === string instead of instanceof.


[#77973] Monday, May 27, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
janiajohnnad

Total Points: 146
Total Questions: 92
Total Answers: 107

Location: Faroe Islands
Member since Thu, Apr 8, 2021
3 Years ago
janiajohnnad questions
Tue, Mar 30, 21, 00:00, 3 Years ago
Sun, Feb 7, 21, 00:00, 3 Years ago
Fri, Nov 6, 20, 00:00, 4 Years ago
Thu, Jun 18, 20, 00:00, 4 Years ago
;