Console logging function name?

Quick question: I was fiddling around, and tried passing around different values for the console log of plantNeedsWater(day).

I noticed that when passing the function without any parameters, it makes sense that the function searches for a string input, finds that it is not Wednesday, and returns the value false.

But why is it that when I type console.log(plantNeedsWater) [notice there are no arguments or parens at the end of the function name], the console displays [Function: plantNeedsWater]?

Screenshot attached for clarity.

When we log just the name of the function, the console logs the Object descriptor. With only the name it treats it as a reference. If we want the function to run, then we need to invoke it with ().

The empty parens means, no arguments so it is seen as an empty parameter list by the function.

That doesn’t mean there are no parameters, though. The function could have default parameters that are filled in positionally by any that may or may not be passed by the caller. This will come up shortly if it hasn’t already.

5 Likes