If I’m passing an object to a case statement, and there is a case where it is undefined, can I handle that case? If so then how? If its not possible, then what is the best practice for handling an undefined case for a switch?
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.
Add a
caseforundefined.Or, if all other options are exhausted, use the
default.Note: To avoid errors, the variable supplied to
switchhas to be declared but can have anundefinedvalue. Reference this fiddle and read more about defined and undefined variables in JavaScript.