We know this is a function because we can call it:
JAVASCRIPT
constgreeting = name => {
console.log(`Hello ${name}`);
}
greeting("John");
BASH
Hello John
However, what if we want to check if the function exists before calling it?
To do this, you can try using the typeof operator:
JAVASCRIPT
constgreeting = name => {
console.log(`Hello ${name}`);
}
if (typeof greeting === "function") {
console.log("This is a valid function")
}
BASH
This is a valid function
Another alternative you could do is simply try calling the function anyways but wrapping it in a try-catch block to catch any potential exceptions that might be thrown: