Jump to content

Var name;


Drycodez

Recommended Posts

var name;

i have seen varibles without value, but i just dont knw why its like that! I was told about it sometime ago, but i still dont understand it.

var car; document.write(car)//prints: undefined.

is it that they want UNDEFINED as the value or what? can somebody be kind enough to help me with this?

Link to comment
Share on other sites

The idea is usually to declare all your local variables at the top of your function, even if they cannot be assigned a value there. This makes sure that you as a developer don't forget to declare the variable locally and accidentally create a global variable later in the body of a function. In JavaScript, unlike other languages, there is no performance difference between declaring a var early or late in a function. It's all about helping you the developer stay organized.

Link to comment
Share on other sites

var a=0; abc(); alert(a)function abc(){ var a=1;}

that means the variable in the abc() function will be a local variable and will not overide the one in the body wright?

vara=0; abc(); alert(a)function abc(){a=1;}

this wil overide the variable in the body wright?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...