Skip to content
Advertisement

Use switch to take in unknown data types, issue with taking in an object

In the below code I am trying to make a switch statement that takes in the following inputs: 34, ’34’, {input: 34}, hello, [“hello”]

and returns the number 34 within each input, the cases I need to have are:

JavaScript

I am having an issue with the object input. Thank you so much!

JavaScript

Advertisement

Answer

You can use typeof result in the switch cases, to determine the output:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement