Creating (declare) Variables


#1

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.


#2

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;

#3

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.


#4

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


#5

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.


#6

var name = ("myColor");
console.log("myColor".length);

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


#7

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

var myColor = "color";

console.log(myColor.length);

#8

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


#9

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


#10

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


#11

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. https://goo.gl/40h6CK