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!

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


Parameter Confusion

Can someone please tell me why the 'greeting' parameter prints out before the 'name' parameter (in the console) from this code:

function sayHello(name ,greeting) {
    if (typeof greeting === 'undefined'){
        greeting = 'Hello' ; 
    console.log(greeting + " World! " + name);

sayHello("Doug", "Greetings");


2 Answers


It's just the way the code is written.

In the console.log function, the first parameter for printing is "greeting", then is the string " World! " and the is the "name" parameter. The function prints the things from left to right.

If this line of code was written like that for example: console.log(name + " World! " + greeting);

then the first output will be the "name" parameter, then " World! " and the last thing will be the "greeting" parameter.

I see, so it's the command that dictates the order...thanks, that's just what i needed!!!