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 Basics (Retired) Storing and Tracking Information with Variables Introducing Variables

duenpun
seal-mask
.a{fill-rule:evenodd;}techdegree
duenpun
Full Stack JavaScript Techdegree Student 1,034 Points

Can I change var('s) value syntax instead of updating it?

in the video : var message = "hello !"; message = "Welcome to Javascript basic ";

Can I change to >>> var message = "Welcome to Javascript basic "; <<< ? instead of updating message's value

2 Answers

Louise St. Germain
Louise St. Germain
19,424 Points

Yes, you definitely can! There's no specific need to set the variable's value to "Hello" first, and then immediately change it to something else. This is just being done as an example here, to show that when you first create the variable, you'd use var [variable name] = [whatever], but later if you want to change the variable's value to something else, you don't put var in front of it. You'd just do [variable name] = [whatever new thing].

As you learn more about JavaScript you'll learn more about variable declarations and scope (plus a couple more ways to declare variables), but for now, at this early stage, all that's important is that you use var in front of the variable name only for the first time you use it, which tells JavaScript you're defining a new variable. (Hence, "var".)

I hope this helps!

no or else only that mesage will apear!