Creating (declare) Variables


I can change value of variable in 26 but can't create the variable in 25/27. Is the code var myName = ("myColor"); ??? Please help.


Declaring a variable means this:

var name;

which means "give me a piece of memory that i can refer to by using name". Currently this variable has a "value" or rather state of undefined. Now you can define it by assigning a value to it e.g.

name = value;

and of course you can do declaration and definition in one step:

var name = value;


It Will not accept this. I did it right in 26, no problem. Maybe a computer error? I even reset. The other codes are correct.


Could you post the code and the error message pls? That would make it easier to see what the problem is.


That seems to be the case quite often. Resetting your current browser session usually fixes any errors you're encountering. But if not I can give you a few other tips that have worked for others.


var name = ("myColor");

Oops, try again. Did you create a variable called myColor?


I think you're speaking like yoda from star wars.

var myColor = "color";



Guess i'm having a bad day! ha Tried that...same error message. Thanks!


Which lesson are you on? I can't do any research if I don't know what the lesson is asking for.


YEAH , I agree... which lesson?? Ive tried that on codecademy labs and its output is 5 which is the length of the word....


You declare a variable when the variable name is following the "var" method: This would create (declare) a variable with the name "firstName" without a value, or the value of null. I found the following information about variables and variable scope in Java Script really useful.