Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Introducing ES2015 The Cooler Parts of ES2015 Arrow Functions

Timothy Mattingly
Timothy Mattingly
15,934 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}! }

greet();

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
56,413 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.