In your use case, you should assume that iconClass is a string. In this case, I would suggest the first if condition. The second option is probably too restrictive; it is usually used only if the person calling the function does not actually pass the third parameter or pass undefined. But if the caller skips an empty or empty line, the first if condition will also capture these conditions. This is the easiest way to write, and it is very easy in Javascript to just check if (variable) { } , because it will catch a lot more and will be very easy to read and write.
if (iconClass) { // Executes if iconClass is not null, not undefined, not 0, and not empty string } if (typeof iconClass != 'undefined') { // WILL execute if iconClass is null, 0, empty string // Only will not execute if iconClass is undefined! }
source share