Modern Programming Languages-Modern Programing Language-Lecture Handout, Exercises of Programming Languages

Modern Programing Language is about different languages of today era. It explains pros and cons of some new languages and their differences with old ones. Languages like java, c sharp, c plus plus, c, fotran are included in this course. This lecture handout is about: JavaScript, Code, terminated, Array, Operator, Arithmetic, Increment, Decrements

Typology: Exercises

2011/2012

Uploaded on 08/04/2012

dhanvin
dhanvin 🇮🇳

4.2

(14)

108 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Modern Programming Languages
Lecture # 38
The <script> Tag
The <script> tag (<script>….</script>) in all major browsers interprets contents as
JavaScript unless one of the following occurs
Inclusion of language attribute
<script language=“VBS”>….</script>
Inclusion of type attribute
<script type=“text/javascript”>….</script>
The type attribute is W3C recommended, it makes the language more common and in
many ways more useful
<script> tag is used to delimit the script code from the HTML
The script tag causes the browser’s JavaScript interpreter to be invoked, the
script run and any output produced
The browser is considered the “host” environment
There are other hosts for JavaScript and its variants
Location of Code
JavaScript may be placed at three places
In the <head> element
Place scripts to be called or when event is triggered here
Ensures script is loaded before called
<html>
<head>
<script type=“text/javascript”>
//script statements
</script>
</head>
Location of Code
In the <body> element
docsity.com
pf3
pf4
pf5

Partial preview of the text

Download Modern Programming Languages-Modern Programing Language-Lecture Handout and more Exercises Programming Languages in PDF only on Docsity!

Modern Programming Languages

Lecture # 38

The ) in all major browsers interprets contents as

JavaScript unless one of the following occurs

  • Inclusion of language attribute

  • Inclusion of type attribute

• The type attribute is W3C recommended, it makes the language more common and in

many ways more useful

Location of Code

• In the element

– Place scripts to be executed when the page loads here

– Script generates some or all of the contents of the page

Location of Code

• External to the HTML file

• Could be in or

• External script should not contain

• Defining Arrays

– var myArray = [1,5,1968,3];

– var myArray2 = [“fakhar”,true,3,-47.2];

– var myArray3 = new Array ();

– var myArray4 = new Array (10);

Arrays

• Arrays in JavaScript are 0 based

• We access arrays by index values

  • var myArray = [1,5,1968,3];
  • myArray[3] is ‘3’

• Difference

  • Array types (composite type as well) are reference types, so problem of aliasing is there var firstArray = [“Mars”, “Jupiter”, “Saturn” ]; var secondArray = firstArray; secondArray[0] = “Neptune”; alert(firstArray); // it has been changed

Operators

• Basic Arithmetic

• Increment decrement

• Comparison

  • < , > , >= , <= , != , == , === (type equality)

• Logical

• Bitwise Operators

– & , | , ^

• String Operator

    • (used for concatenation)
  • document.write(“JavaScript” + “is” + “great!”);

Type Conversion

• Converting one type of data to another is both useful and a source of

numerous errors in JavaScript

– var x = “10” – 2 ; //result is 8

– var x = “2” – “2” ; //result is 0

– var x = “2” + “2” ; //result is “22”

Control Statements

• If

• Switch

• While

• Do-while

• For

• Continue

• Break

• For (in)

Labels and Flow Control