The only way to categorically confirm whether all of these values is defined, regardless of type, is this:
if( (typeof a !== 'undefined') ||
(typeof b !== 'undefined') ||
(typeof c !== 'undefined')) { /* ... */ }
Unfortunately, shortcuts that rely on truthiness of values and, as you point out, this is not always an acceptable approach.
As Alex K shows, you can do some tricky stuff if you know the type of the variable beforehand, but knowing the type beforehand may require as much code as you avoid in the comparison.
Edit 1
Dave Newton pointed out that prompt
always returns a defined value; it returns null
if user's press cancel.
Thus, a better approach would be:
function isValid(value) {
return typeof value !== 'undefined' && value !== null);
}
if( isValid(a) && isValid(b) && isValid(c) ){ /* ... */ }
Edit 2
Of course, the simplest thing to do is to check for validity before parsing the ints. Since
!!"" === false
!!"0" === true
!!0 === false
You can use (a && b & c)
on the string/null that prompt returns and only if they are valid, do your parsing.