In computer science, the syntax of a computer language (aka programming language ) is the set of rules that defines the structure of a programming language. And a computer programmer should follow these rules in order for the program to work.
In a programming language, variables are used to store data.
Data is anything that is meaning to a computer.
An important part of programming is learning how to save data.
Variables are easy to create.
An equal sign is used to assign values to variables.
var a; a = 5;
In the example above var a; means there is ‘a variable’ called ‘a’
And a = 5; means its value or data is 5
Where to put your scripts?
You can place your scripts in any of the following locations:
- Inside the HTML document’s
- Within the HTML document’s body (i.e. between the
- In an external file (and link to it from your HTML document) using
For example, the variable
myName must be typed exactly as
Similarly, the method name
getElementById() must be typed with the exact case, not as
var myName = "Lia Sue Kim"; console.log(MyName);
If you checkout the browser console by pressing the
f12 key on the keyboard, you’ll see a line something like this:
Uncaught ReferenceError: MyName is not defined