Intro to JS - Part 8/11 - Function Expressions - log false


#1

Hi!

I just finsihed the part 8/11 of the interactive lesson Introduction to Javascript on function expressions.

I was modifying the code to check the logs, and I don’t understand why the console log false after running the code below :

const plantNeedsWater = function (day) {
  if (day === 'Wednesday') {
     return true;
     } else {
       return false;
     }
}

plantNeedsWater('Wednesday');

console.log(plantNeedsWater());

Just keep in mind that I’m a beginner and this is my first post… many thanks for your replies.

hlf


#2

here:

console.log(plantNeedsWater());

you call the function for a second time, but this time, you didn’t provide an argument for the parameter, so JS will use undefined as parameter value

In many languages, this would give you an error. JS just “fails” silently by providing a default value for parameter


#3

Ok, I get it.

Thanks for the explanations.