You are on page 1of 4

P3

Jamal Al-Attar

Scripting Languages
Scripting languages provide benefits and features for the developer that cannot
be added by something such as HTML or CSS. These features will also benefit the
visitor of the website by performing tasks such as redirecting them to new pages
when old ones are deleted or having validation rules on forms.
Web Servers and Programming Languages
Using scripting languages (specifically JavaScript) is beneficial compared to a
programming language that would run on a web server. This is because
JavaScript can be run locally on the users computer, and no or little data needs
to be sent to and back from the web server. This is advantageous because it
means there will be less stress on the web server, especially if there is a large
amount of users. A small thing such as validation for username length does not
need to be sent to a web server, so it would a waste of bandwidth if it was sent.
This will result in lower costs as a less powerful web server will be required.

Characteristics of Scripting Languages


JavaScript Object Oriented and Event Driven
JavaScript is both object oriented and event driven. It is object oriented because
developers are able to define data types, structures as well as functions for a
data structure. The data structure is the object that can have data and functions
included in it. It is also event driven because it is commonly used in web pages
where HTML cannot be used such as in forms. It allows for the user to perform an
event such as a click of a button for data to be submitted.

Event Handlers and how they are triggered


An event handler is a function that is executed in response to an event. Events
are user inputs that are often in the GUI. An example of an event would be
actions such as the click of a button, or a keystroke. This is a characteristic of
JavaScript. In the majority of situations, the JavaScript will have an event handler
that is waiting for the user to perform an event, such as clicking the Submit
button on a form.

JavaScript Security Issues and how to overcome them


There are a few security issues with JavaScript which can endanger the users
data or cause damage to their computer if used for malicious reasons. This is
because local JavaScript is stored and executed on their computer, so it is
susceptible to damage. Although, damage control is in place and so malicious
actions are limited and vulnerable features are limited to ensure the most safety
for the user.
It is possible for new windows to be opened to direct the user to a new website
that they did not want to go to. This could be for various reasons such as
advertising revenue, spam, or even taking user information such as their IP.

P3

Jamal Al-Attar

Here is the code that is used to open a new window it can be linked to any page
that is specified by the developer.

How to include JavaScript in a web page


JavaScript is easy to implement into a HTML page by using the <script>
</script> tags. Everything that is between these tags is recognised as script by
the browser and it will be used when the function is called. The script must also
be between the <head> </head> tags so it can be distinguished from the HTML.

Scripting Language Constructs


Syntax
The assignment operator in JavaScript is used to give a value to variables. It can
be used for equations such as below.

Decision making (if/else)

Var is used to call a variable for


the first time. Price1 will be
given a value, in this case 5, as
well as Price2 6. When the
variable total is called, it will add
Price1 and Price2.

In JavaScript, sometimes decisions need to be made that are dependent on a


specified condition. For example, if there was a number game where a user must
guess the random generated number by the JavaScript, there must be an if/else
statement to give two different outcomes dependent on the condition (the user
enters the correct number). If the user guesses the number correctly, they will
get congratulations pop-up, and if it is incorrect, they will receive a pop up telling
them the correct answer.

P3

Jamal Al-Attar
Conditio
n
Display if guessed
correctly
Else, display unlucky
message

Functions
A JavaScript function is a selection of code that is created to perform a specific
task when it is called. Functions may sometimes require data that needs to be
input or created before the function works properly. The data values that are
required are called parameters. After the function has been named, the
parameters can be included between brackets afterwards.
This is an example of code that contains two parameters.

Methods
JavaScript methods are functions that are formed to be part of an object. The
most commonly used ones are the following:
Write() Write is often put in conjunction to document (the web page) to
display text on the web page for the viewer. In this code, the web page will
display Hello.

Click() Click is used for detecting mouse clicks by the user. For example, to
detect the user clicking a button, onClick() will be used. This code will detect a
click from the user on a button that says Click me.

Open() Open is used for opening a new window in a browser. The developer is
able to specify which website or link is opened. In this code, a new window is
opened test.html.

P3

Jamal Al-Attar

You might also like