New to javascript, I face many problems.
I read the javascript tutorial at w3cschools.com,
and there are many question marks on my head.
I do not understand what is the difference below:
var name=something;
name=something;
The above two examples also giving something to a name, why 2 different ways?
name=new Array();
name[0]=something0;
name[1]=something1;
is this same with switch?
//switch start
var name=something();
switch(something)
{
case 1:
do something;
break;
case 2:
do something;
break;
default:
do something;
}
//if…else start
var name=something();
if (condition)
{
do something
};
else if (condition)
{
do something
};
else
{
do something
};
what is the different between switch case and else.if ?
i think both 2 is doing the same thing?match condition and then do something?
and the for Loops,while Loops and break Loops ,
both 3 are doing the same thing,but 3 different ways.
can someone tell me what is the different between them?it make me confuse.
and please intro more tutorial for javascript.
many thanks here
In answer to your first question:
var name
This snippet creates a new variable, called name. It will be refered to in the rest of your code as name, it has been declared.
var name = something
This piece of code assumes that there is a variable declared above it called ‘something’, and it creates the name variable and assigns it the value of whatever ‘soemething’ holds at that particular point.
name = something
Without the intitial creation of the variable, this line assumes that the variable has already been declared previously, it is simply assigning that variable the value or something.
Reading
I recommend you read this webpage which appears to have a great introduction to javascript and will answer many more of your questions.