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 trialJoshua Martin
18,331 PointsCan you explain the why behind variables inside of var?
Can anybody explain why you would create variables inside of other variables, and give some examples? Thanks! Jiles
1 Answer
Tushar Muhammad
Full Stack JavaScript Techdegree Student 508 PointsVariables are never created inside variables. variables contain things called objects like strings, integers or floating numbers or any sort of input. For example, Greeting = input("What's up?") here, 'Greeting' is the variable and it contains the string the user responds with to the question "What's up?"
Another example, Greeting = "Welcome to Palm City Beach!" here, 'Greeting' is still the variable but it contains a different value. Instead of an input, it contains a string.
Btw, strings are just alphanumeric characters and r always enclosed in quotation marks.
For example, firstName = input("what is your first name?") print( "Hi my name is", firstName)
in the function print, the string is "Hi my name is" and 'firstName' is the variable.
Steven Parker
231,268 PointsYou might say that object properties are "variables inside of other variables". For example, "name" and "age" are both inside "person":
var name = "Joe";
var age = 22;
var person = { name, age };
console.log("The person's name is " + person.name);
console.log("and they are " + person["age"] + " years old.");
But I'm not sure that was the original question since I don't see how it would relate to this video.
Ankush Sharma
844 PointsAnkush Sharma
844 PointsHe is asking about reassigning the variables.Can you please explain on that?