Docsity

JavaScript: Understanding Client-Side Scripting with Javascript, Slides of Computer Science

Partial preview of the text

Download JavaScript: Understanding Client-Side Scripting with Javascript and more Slides Computer Science in PDF only on Docsity!

CONTENTS

JAVASCRIPT and WHAT CAN IT DOMost popular scripting language on the internet and works in all major browsers such as internet explorerUsually embedded directly into web pagesIt is an interpreted languageIt gives HTML designers a programming tool.It can put dynamic text into an html pageIt can react to eventsIt can read and write HTML elementsCan be used to validate data.Can be used to create computer

Advantages

of

javascript

Speed

being client side, javascript is very fast because any code functions can be run immediately instead of having to contact to the server and wait for an answer.Simplicity

javascript is relatively simple to learn and implement.Versatility

javascript plays nicely with other languages and be used in a huge variety of applications.Server Load

being client –side reduces the website server.Easy to debug and testingNo special editor is required for it.

How

to

add

HTML

tags

to

the

javascript

**_To insert a javascript into an HTML page , we use the

EXAMPLE

< script type=“text/JavaScript”> document.write(“Hello World!”);

JavaScript

Comments

 Single line comment start with

 Example //write a heading  Javascript multiple line comments start with

and end with/.  Example /the code will write one heading and two pragraphs.*/

Javascript

operators

 Arithmetic operators  Assignment operators  Comparison operators  Logical operators  Conditional operator

Assignment

operators:X=10,Y=

OPERATOR EXAMPLE SAME AS RESULT = X=Y X= += X+=Y X=X+Y X= ‐ = X ‐ =Y X=X ‐ Y X= = X=Y X=X*Y X= /= X/=Y X=X/Y X= %= X%=Y X=X%Y X=

Comparison Operators : X=

Alert

Box:

 An alert box is often used if you want to make sure information comes through to the user.  When an alert box pops up, the user will have to click “OK” to proceed.  Syntax

alert(“sometext”);

Confirm

Box:

A

confirm box is often used if you want the user to verify or accept something.  When a confirm box pops up, the user will have to click either

“OK”

or “cancel’ to proceed.  If the user clicks

“OK”,

the box returns true. If the user clicks “cancel”, the box returns false.  Syntax

confirm(“sometext”);

Javascript

functions

A

function contains a code that will be executed by an event or by a call to the function.  We may call a function from anywhere with in a page  Functions can be defined both in the

and in the

section of a document  Syntax

Function function name(var1, var2…varx) { Some code }

Example

of

function