JavaScript JavaScript Basics Storing and Tracking Information with Variables Introducing Variables

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
17,946 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!