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 JavaScript Loops, Arrays and Objects Tracking Data Using Objects The Build an Object Challenge, Part 2 Solution

Kevin Alvarez
Kevin Alvarez
4,851 Points

Variables and Parameters

var message = ''; var student;

function print(message){ var outputDiv = document.getElementById('output'); outputDiv.innerHTML = message; }

If using the same word for a variable and a parameter, does it hold the same value?

3 Answers

Erik Nuber
Erik Nuber
20,629 Points
var message = ''; 
var student;

function print(message){ 
    var outputDiv = document.getElementById('output'); 
     outputDiv.innerHTML = message; 
}

In this case yes, the variable that is stored in the function message will be the same value as what is sent it. ie to call you could say

print(message);

or

print(student);

what you call the variables inside the function could be anything so message could just be X but, it is best to use something meaningful.

It is also important to remember scope.

variables declared outside of all functions have global scope. So if you declared another variable within the function called message, it would hold different values because inside the function it is local scope.

Kevin Alvarez
Kevin Alvarez
4,851 Points

Thanks Erik, There is so much to learn with JavaScript. After every video i watch i feel like i know less and less, but thanks again for the help!

Erik Nuber
Erik Nuber
20,629 Points

You'll be fine, some of those I have watched over and over and, even after finishing my portfolio I am back to rewatching them because there is so much I haven't used that I want the refresher.