Javascript String Type check if a variable is a string
let a = String("I'm a String Object"); let b = "I'm a string literal"; let c = 7; //from ww w .j a v a2 s. c om let d = new Date(); if ( typeof a === 'string' ) { console.log("a is a String"); } else { console.log("a is not a String"); } if ( typeof b === 'string' ) { console.log("b is a String"); } else { console.log("b is not a String"); } if ( typeof c === 'string' ) { console.log("c is a String"); } else { console.log("c is not a String"); } if ( typeof d === 'string' ) { console.log("d is a String"); } else { console.log("d is not a String"); }