How can I determine whether a variable is a string or something else in JavaScript?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use
typeofoperator:Example from this webpage. (Example was slightly modified though).
This won’t work as expected in the case of strings created with
new String(), but this is seldom used and recommended against[1][2]. See the other answers for how to handle these, if you so desire.