In this case you can use a === undefined
comparison: if(val === undefined)
This works because val
always exists (it's a function argument).
If you wanted to test an arbitrary variable that is not an argument, i.e. might not be defined at all, you'd have to use if(typeof val === 'undefined')
to avoid an exception in case val
didn't exist.