To see if the argument has a usable value, just check if the argument is undefined. This serves two purposes. It checks not only if something was passed, but also if it has a usable value:
function alertStatement(link) {
if (link !== undefined) {
// argument passed and not undefined
} else {
// argument not passed or undefined
}
}
Some people prefer to use typeof like this:
function alertStatement(link) {
if (typeof link !== "undefined") {
// argument passed and not undefined
} else {
// argument not passed or undefined
}
}
null
is a specific value. undefined
is what it will be if it is not passed.
If you just want to know if anything was passed or not and don't care what its value is, you can use arguments.length
.
function alertStatement(link) {
if (arguments.length) {
// argument passed
} else {
// argument not passed
}
}