banner
Javascript

Javascript is nothing to do with Java (which came first). Javascript gets your web browser to do amazing things with elements on a webpage.

Here are some tips for getting started with JavaScript:

Inline Script
This is the easiest way to include JS in your page
You must use the <script> tag in your HTML file to link to the separate the JS from HTML
This image below shows a basic html page with a JS script The script tag can appear anywhere in the file but it is important to understand that the code is processed in the sequence it occurs in the file
Attached Script File
Keeping JavaScripts in external files has some advantages:
  • It separates HTML and code
  • It makes HTML and JavaScript easier to read and maintain
  • The same JS code can be used by a number of HTML files and there is only one copy of the code file

Here is a basic html with an attached JS script
Running the program
Have a way of calling the code
1. Inline code executed as part of the page loading (as above)
2. Calling a function as part of the <body< tag: <body onload="procedure_name()">
3. When a button is pressed:
<button type="button" onclick=" procedure_name()">Click Me!</button>
Statements
JavaScript programs are free format. For readability though, put each statement on a new line and use indents to show program logic.
All statements must end with a ; (semi-colon)
Variables
Before you use a variable in a JavaScript program, you must declare it.
Variables are declared with the var keyword as follows:
var width;
var length;
Variables in JavaScript are not explicitly typed i.e. you don't have to declare them as integer or string for example.
Datatypes
Variables in JavaScript are not explicitly typed i.e. you don't have to declare them as integer or string for example.
However it is important to know how JavaScript will treat your variables.

Open up a basic HTML/Javascipt page to edit here