I’m displaying a text value and if by coincidence that text value happens to be numeric, then JavaScript displays it with a decimal .0.
Q: How do I write:
if (X is numeric) {
$('#Status').text(+X);
} else {
$('#Status').text(X);
}
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
typeofto determine the type of value that a variable stores:The cool thing about
typeofis that it always returns a string so even if the variable you are checking is not set you will just get the stringundefined.Here are some good docs for
typeof: https://developer.mozilla.org/en/JavaScript/Reference/Operators/typeof