Syntaxes are simply the rules in which the programs of a programming language should be written.
If your programs are written on a webpage e.g mywebpage.html
, they must be contained in the HTML <script>
element else the codes won't be executed because they won't be recognized as JS codes.
, then, no need enclosing them inside the <script>
element since the file is a script and not a webpage that understands HTML markups.
- this script won't work
- CORRECT WAY
var num = 56
var num = 56;
- Ensure you declare any variable you assign a value to it with the var keyword
- Ensure you assign a value to a variable before using it else it becomes undefined.
- Be careful so that you don't name two variables that are suppose to be different with same name.
- A syntax is a rule that guides the composition of the programs of a programming language.
- Statements are instructions given to computers or browsers to do something.
- We use variables to store and give names to values.
- Before you give a value to a variable, ensure it has been declared using the var keyword.
- Before you use a variable, ensure it contains or you have given a value to it.
- Be careful not to give variables that should be different same name. The variable simply carries the last value that was given to it while the previous gets lost.