The other type of programme is 'server-side', which works by interacting with the server online. Examples of server-side programmes are: PHP, .NET, Ruby on Rails, ASP, ColdFusion. MySQL is a 'structured query language' allowing data to be input, edited and extracted from a database on a server.
These days of highspeed internet connections, this often happens so smoothly and seamlessly the client is unaware of the complexity of the action on his or her screen.
The 'alert' inside the tags is a function. Functions can be custom-made or built in already to browsers, so they know what to do when they come across one with this name. The function 'alert' brings up a pop-up window on the screen containing the message inside the parentheses and quote marks.
It is good practice to separate structure (the basic HTML page) from its styling (CSS) and function (JS), by including external CSS and JS files. An included JS file should not have opening and closing
<script>...</script> tags, since the HTML file calling the script has already opened the them.
There is a need to consider the timing of the download of external JS files. The sequence may be important, and it may be advantageous (or necessary) to prevent the script from running till after the whole page has been downloaded and parsed. There are two attributes which control the behaviour and timing of external JS file downloads and execution:
defer attribute appears in
script tag. It signals the browser to download the file, but not to attempt to run the code until after the page has rendered. If there is more than one
defer flagged scripts, then the scripts will be executed in the sequence they appear, and before the
DOMContentLoaded event. Best practice is to place all scripts with
defer attributes at the end of the file, and not use both
DOMContentLoaded events, to avoid clashes.
async attribute does the opposite of
defer: it loads and begins to execute the JS file immediately. They execute before the load event, but may execute after the
DOMContentLoaded event. It is safest to use the
async attribute only with files which do not modify the DOM as they load.
A common application of
++ is the
count in a
++i will increase the value of the variable
i with each iteration of the
loop. If the initial value
i = 1, by setting a conditional for the loop as:
for(i=1; i<=10; ++i )
The loop will run up to 10 times before exitting.
Assignment operators assign values to variables.
|a = x||assigns the value ||a=12||12|
|a += x||increments current value of ||a += 1||6|
|a += 'string'||concatenates the string to variable ||a+= ' plus VAT'||5 plus VAT|
|a -= x||subtracts value ||a-=1||4|
|a *= x||multiplies current value of ||a*=2||10|
|a /= x||divides current value of ||a/=2||2.5|
|a %= x||returns ||a%=2||1|
In Example 1,
valueA is decremented in the statement
var valueC = --valueA + valueB;, and this value (5) is used in any subsequent statement.
In Example 2,
valueA is decremented in the statement
var valueC = valueA-- + valueB; after the calculation of
A useful way to control and safeguard the effective running of a script is to create a custom function to be called when an error is detected:
A more flexible system for handling errors uses the keywords
catch. These keywords allow the script to control how errors are handling for individual sections of code rather than the previously described global
catch(err) is run only if
try encountered an error.
finally is optional, and is run in every case, regardless of whether
try encountered an error or not.
Often, it is necessary to redirect the URL from one page to another. This can be accomplished in JS by simply writing a condition which, if true, will execute this code:
window.location = "http://www.newurl.com";
Application Programming Interface: the set of routines, protocols and tools used in constructing software applications. API is used for programming GUI (graphical user interface) components, and specifies how the various software components of a complex programme should interact.
"ECMAScript was originally designed to be a Web scripting language, providing a mechanism to enliven Web pages in browsers and to perform server computation as part of a Web-based client-server architecture. ECMAScript can provide core scripting capabilities for a variety of host environments, and therefore the core scripting language is specified in this document apart from any particular host environment."
Content © Andrew Bone. All rights reserved. Created : June 1, 2014 Last updated :March 10, 2016
The most recent article is:
View this item in the topic:
and many more articles in the subject:
1862 - 1943
David Hilbert, 1862 - 1943, was German, and is considered one of the greatest mathematicians ever, leaving a broad legacy in mathematics, physics and philosophy.
Like wine through water, it has altered the colour of my mind.
Website © contentwizard.ch | Designed by Andrew Bone