I have a JavaScript function in which someone can pass something and I iterate over each of his keys with
for x in obj
syntax. However, this results in an error if they pass a primitive (string or number); the correct behavior is for the function to act in exactly the same way as on an object without keys.
I can do a try..catch block to get around this, but is there any other (more concise) way?
javascript
Trevor burnham
source share