To check if a variable is a string, you can use the
// Check if variable is a string const str = "Hello World!"; typeof str; // string
- The operator will return the type of the variable as a string, in our case, it will be a
See the above code live in JSBin.