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

General Discussion

troy beckett
troy beckett
12,035 Points

help with javascript..

Just starting to learn javascript and I'm can't really understand something:

var part1 = "Team ";

function bam() { var part2 = "Treehouse"; }

bam(); **********************************

console.log(part1);

in the code above where put the *********** what does this line do and why do you need it.

2 Answers

That line calls function bam which assigns "Treehouse" to part2 variable.

Vance Rivera
Vance Rivera
18,322 Points

bam() is the function call. When you declare the function above the code does not actually do anything until you call it to execute the code within the function. To practice take out the type var part2 and change the variable to part1 = "Treehouse". You will notice that the console.log will display "Treehouse" instead of "Team" this time. Next remove the call to the function bam right before your console.log and refresh your page and you should see the word "Team" from the console.log. This will demonstrate to you what happens when you have a function but it is not being called. Hope this helps.