JavaScript Introducing ES2015 The Cooler Parts of ES2015 Arrow Functions

Timothy Mattingly
Timothy Mattingly
10,486 Points

What makes these variables not truthy?

So, this lesson is on default parameters. in the file you have:

function greet(name, timeOfDay) { name = name || 'Guil'; timeOfDay = timeOfDay || 'Day'; console.log(Good ${timeOfDay}, ${name}! }


He says, the double pipe checks the variable and returns the value of the variable if it's truthy. Otherwise, it returns the default value on the right side. When you run the file in the console, it returns, Good day, Guil!

It appears to me that the default variables got returned. Why is that when the names of the variables match the variables being passed into the function??

1 Answer

Seth Kroger
Seth Kroger
Treehouse Moderator 56,266 Points

You're not passing anything into the function because the call greet() has no arguments. This make the two parameters undefinded which is falsey.