Knowing how to use syntax and not to use it is the biggest hurdle in understanding JavaScript. A full understanding of the concepts will be key. Try to force yourself not to move forward till you have a clear awareness of the current topic.
Variables are one of the most important aspects of general programming. Variables are used to represent a value. In math you have seen these used in formulas. The fundamental concept is the same.
What is an Identifier?
A Identifier is the physical name of the variable.
What is a Variable?
A Variable is the pointer to a value.
Think of a Variable as a representation of a value an not a value itself. How a phone number will connect you to a certain phone. A Variable will connect you to a certain value.
The syntax. – The ‘var’ syntax lets JavaScript know you will be defining a variable. After ‘var’ you will make a space followed by the identifier’s name also known as the variable name. We then end the line with a semi-colon
var aVariableName;
At this point the variable ‘aVariableName‘ would not be defined. This means it has no set value.
Assigning a value to a variable is done with a single equal sign. Now the variable ‘aVariableName’ would be equal to “a value”. So here we are defining a variable with the identifier as “aVariableName” and assigning its value to “a value”.
var aVariableName = "a value";
You only need to define the variable once within it’s scope. We will discuss scope in detail at a later point in this JavaScript lesson.
When NOT to use var.
…..