Javascript syntax and basics: Javascript is as easy the language as useful it is. Before we wish to add some Javascript code to our webpages, we have to create a Javascript file e.g. main.js or primay.js or anything.js whatever the name you may like to use. After creating the .js file in a notepad or text document, we shall include it in our web document in the following manner:
<script src=”includes/main.js“></script>
In above example, we are including our “main.js” file from the folder “includes” at the root of our website. The “<script src” is the syntax for including and running JavaScript code into web pages.
Hint: Compare it to a CSS file and you would realize that it is just like including CSS file where we use <link rel>
The <script> command executes the contents within “main.js” file after loading it.
Things to remember while working in JavaScript environment:
Every JavaScript line ends on a semicolon. Every variable’s value must be within quotes; either single quotes or double quotes.
JavaScript in case sensitive. So, myname and Myname are two different variables.
While assigning numeric values to the variables, don’t use quotes. Numbers go without quotes.
Hyphens(-) are JavaScript reserved characters and cannot be used in variable names.
Variables can be called anywhere in the program to get the value associated with them.