0
How to return a number if possible, else a string.
Is it possible (in Javascript) to create a function with an argument n that returns the number n if it's possible to convert it to a number, else the string n? Example of what i mean : numberIfPossible("4"); //returns the number 4 numberIfPossible("text"); //return the text "text"
2 Answers
+ 3
yes.
Use the isNaN function.
0
That worked. Thank you.