Unit I PPT CSS 1
Unit I PPT CSS 1
1
• Create interactive web pages
CO1 using program flow control
structure
2
TEACHING AND EXAMINATION SCHEME
3
What is JavaScript Programming?
What are the features of JavaScript?
4
CONTENTS
1. Features of JavaScript
5
Department of Information Technology,Government
Polytechnic Awasari(kh)
JAVASCRIPT
1.Concept of JavaScript
2. Features of JavaScript
3. Limitations of JavaScript
4. Advantages of JavaScript
6
Department of Information Technology,Government
Polytechnic Awasari(kh)
JAVASCRIPT
• JavaScript is an open source & most popular client side scripting language
supported by all browsers.
• JavaScript is a very powerful client-side scripting language.
• JavaScript is used mainly for enhancing the interaction of a user with the
webpage.
• You can make your webpage more lively and interactive, with the help of
JavaScript.
7
Department of Information Technology,Government
Polytechnic Awasari(kh)
FEATURES OF JAVASCRIPT
1. JavaScript is an object-based scripting language.
5. It is light weighted.
10. Most of the JavaScript control statements syntax is same as syntax of control
statements in C language.
8
Department of Information Technology,Government
Polytechnic Awasari(kh)
LIMITATIONS OF JAVASCRIPT
1. Client-side JavaScript does not allow the reading or writing of files. This
has been kept for security reason.
9
Department of Information Technology,Government
Polytechnic Awasari(kh)
ADVANTAGES OF JAVASCRIPT
1. Less server interaction − you can validate user input before sending the
web page to the server. This saves server traffic, which means less loads
on your server.
2. Immediate feedback to the visitors − they don't have to wait for a page
reload to see if they have forgotten to enter something.
10
Department of Information Technology,Government
Polytechnic Awasari(kh)
JAVASCRIPT TAG
• You can place the <script> tags, containing your JavaScript, anywhere
within your web page, but it is normally recommended that you should
keep it within the <head> tags.
• The <script> tag alerts the browser program to start interpreting all the
text between these tags as a script.
<script ...>
JavaScript code
</script>
11
Department of Information Technology,Government
Polytechnic Awasari(kh)
JAVASCRIPT CODE
1.Language − This attribute specifies what scripting language you are using.
Typically, its value will be JavaScript
2.Type − this attribute is what is now recommended to indicate the scripting
language in use and its value should be set to "text/javascript".
Example
<script language = "javascript" type = "text/javascript">
JavaScript code
</script>
JavaScript Code:
<html>
<body>
<script language = "javascript" type = "text/javascript">
document.write("Hello World!")
</script>
</body>
</html>
12
Department of Information Technology,Government
Polytechnic Awasari(kh)
OBJECT NAME, PROPERTY , METHOD ,DOT SYNTAX,
MAIN EVENT
Object Name :
• A JavaScript object is a collection of named values and these named values are
properties of object .
• Each object should be uniquely identified by a name or IDs in web page to
distinguished between them.
• JavaScript supports various objects like document , form ,button , window etc
• In JavaScript , object can be created with curly brackets { } with an optional list of
properties.
• Example:
<script language=“Javascript” type=“text/javascript”>
var student= {
name:”vijay”,
age:21,
year:”TY”
};
</script>
13
Department of Information Technology,Government
Polytechnic Awasari(kh)
PROPERTY
• A property is a value associated with an object.
• Every object has its own set of properties for example window has properties like
width, height, background color.
• A property is a “key: value” pair,
1. key (property name) is always a string
2. value (property value) can be any data type like strings, numbers, Booleans
Program: Write a Javascript code to declare property
<html>
<head>
<title>object property</title>
<script language=“Javascript” type =“text/javascript”>
Var student ={
name:”vijay”,
age:21,
year:”TY”
};
document.write(student.name);
</script>
</head>
<body>
14
</body> </html>
Department of Information Technology,Government
Polytechnic Awasari(kh)
METHOD
15
Department of Information Technology,Government
Polytechnic Awasari(kh)
DOT SYNTAX AND MAIN EVENT
Dot syntax:
• One can access an object’s properties and methods by using the dot syntax
along with the object name and its property and method.
• For example, the write method for a document: document. write()
• The first part is the name of the object (document) and second part is either
a property or method (write) of the object.
Main event:
• In Javascript, an event is the way to start executing your code like on mouse
click, button click etc.
• Javascript reacts to event with the help of event handling.
• Event handling is the execution of code on occurrence of event. For
example- when click on submit button then the event handler for that click
event should process the information.
• The function written for event handling are known as event handler.
16
Polytechnic Awasari(kh)
VALUES AND VARIABLES
• Javascript is a dynamic language because a variable can hold value of any
data type at any point of time.
• Var keyword is used to specify the data type. It can hold any type of values
such as numbers, strings etc.
Following are the values used by Javascript
1. Number- A number is a numeric value. for example: var a=20;
2. String- A string a sequence of characters that is enclosed within quotation
marks. For example: var city=“pune”;
3. Boolean- A Boolean is a value-either false or true. for example: var b=true;
4. Null- Null value means no value at all. For example: var i=null;
5. Objects- An object is a instance through which we can access members.
for example: var person={first name : ”john”, last name :”doe”};
17
Polytechnic Awasari(kh)
OPERATORS
• Operators are the symbols which indicate operations to be performed.
• Operands are the variable on which operation to be performed.
• The systematic arrangement of operators and operands is known as
Expression.
There are following types of operators in JavaScript.
1. Arithmetic Operators
2. Comparison (Relational) Operators
3. Bitwise Operators
4. Logical Operators
5. Assignment Operators
6.Conditional Operators
18
Polytechnic Awasari(kh)
ARITHMETIC OPERATORS
19
Polytechnic Awasari(kh)
ARITHMETIC OPERATORS- PROGRAM
<html>
<body>
<script type = "text/javascript">
var a = 33;
var b = 10;
var c = "Test";
var linebreak = "<br>";
b = --b;
document.write("--b = "); result = --b; document.write(result); document.write(linebreak);
</script>
</body>
</html>
20
Department of Information Technology,Government
Polytechnic Awasari(kh)
COMPARISON OPERATORS
21
Polytechnic Awasari(kh)
COMPARISON OPERATORS- PROGRAM
<html>
<body>
<script type = "text/javascript">
var a = 10;
var b = 20;
var linebreak = "<br>";
22
Polytechnic Awasari(kh)
BITWISE OPERATORS
23
Polytechnic Awasari(kh)
BITWISE OPERATORS: PROGRAM
<html>
<body>
<script type = "text/javascript">
var a = 2;
var b = 3;
var linebreak = "<br>";
24
Polytechnic Awasari(kh)
LOGICAL OPERATORS
PROGRAM:
<html>
<body>
<script type = "text/javascript">
var a = true;
var b = false;
var linebreak = "<br>";
document.write("(a && b) => "); result = (a && b); document.write(result); document.write(linebreak);
document.write("!(a && b) => "); result = (!(a && b)); document.write(result); document.write(linebreak);
</script>
</body>
</html>
25
Polytechnic Awasari(kh)
ASSIGNMENT OPERATORS
26
Polytechnic Awasari(kh)
ASSIGNMENT OPERATORS: PROGRAM
<html>
<body>
<script type = "text/javascript">
var a = 33; var b = 10; var result;
var linebreak = "<br>";
document. Write("Value of a => (a = b) => ");
result = (a = b); document.write(result);
document. Write(linebreak);
document. Write("Value of a => (a += b) => ");
result = (a += b); document.write(result); document. Write(linebreak);
document. Write("Value of a => (a -= b) => ");
result = (a -= b); document.write(result);
document. Write(linebreak);
document. Write("Value of a => (a *= b) => ");
</script>
</body>
</html>
27
Polytechnic Awasari(kh)
CONDITIONAL OPERATOR
result = (a > b) ? a : b;
document.write("Greatest Number="+result);
</script>
</body>
</html>
28
Polytechnic Awasari(kh)
QUIZ TIME
Q1. Which JavaScript is also Q2 . What should appear at the very end
called client-side JavaScript? of your JavaScript?
The <script LANGUAGE="JavaScript">tag
a) Microsoft
b) Navigator A. The </script>
c) LiveWire B. The <script>
d) Native C. The END statement
D. None of the above
29
Department of Information Technology,Government
Polytechnic Awasari(kh)
QUIZ TIME
Q3. Which of the following best Q4. What is the correct JavaScript
describes JavaScript? syntax to write "Hello World"?
A. System.out.println("Hello World")
A. a low-level programming language.
B. println ("Hello World")
B. a scripting language precompiled in
C. document. Write("Hello World")
the browser.
D. response. Write("Hello World")
C. a compiled scripting language.
D. an object-oriented scripting language.
30
Department of Information Technology,Government
Polytechnic Awasari(kh)
THANK YOU
Thank You
31
Polytechnic Awasari(kh)