Mistaking syntax in programming called syntax error.
var varName; or
var varName1, varName2, varName3, ...; See detail example below:
var mike; // single variable without value var mike, bob, alex; // multiple variable without value var mike = 12; // single variable with value assigned var mike = 12, bob = 15, alex = 23; //multiple variable with value assigned
var keyword is used to define variables. We will learn everything about variable in a later chapter.
= ) sign.
In the above example, notice that we have put a semi-colon ( ; ) after every statement defined. It actually refers to terminate a statement.
The equal to (
var myVar = 10; here (
= ) does not mean equal to. It means
10 will be assigned to
//It is comment and it is not interpreted by JS interpreter. /* This is multi-line comment for writing large comment */ document.GetElementbyId.innerHTML("Hello, World"); //another comment
/* ... */ or after
We will learn more about comment in later chapters
var myVar = 10; here
myVar is the declared variable and it is also called an identifier.
There are some rules you have to follow before defining an identifier. We will learn them in a later chapter.
var myVar; here
var is the only keyword you have to use to declare variables.
Similarly, function is a keyword for defining function,
Myvar is different variable identifier.