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

Jonathan Whelchel
2,096 Pointsvar versus =
what is the difference between
var str = "playground"
and
str = playground
3 Answers

Michael Hulet
47,909 PointsThe first one is creating a new variable str
and assigning the String value of "playground"
to it, but the second one is assigning the value of the already-created variable playground
to the also already-created variable str

Jonathan Whelchel
2,096 PointsI still don't get it...

Jonathan Whelchel
2,096 PointsWhat I'm saying is why do var at all when I can just do str =

Michael Hulet
47,909 PointsBecause you can't do just str = whatever
. Using the var
keyword sets up the variable to be used for the first time. After that, you shouldn't use the var
keyword, because that's only used for creating new variables