Angular
Angular
applications
Web development
Front end
Back end
Data server
Client side scripting
Server side scripting
3
Types of Applications
Windows applications
Web applications
4
Windows applications
5
Web Applications
6
Guess this?
7
What is this?
8
Website Vs Web applications
9
Windows Vs web applications
10
11
12
13
14
15
16
Introduction
Web page uses
HTML, for its content, layout and structure
CSS for its presentation
Script adds behavior to this web page.
All
mentioned below are added to a web
page using a script / Common uses of script
Customized content based on user input
Dynamic content
Form validation
17
What is a Script
A script is a set of instructions to be executed
by a computer
A script needs an interpreter and is
interpreted at run-time
A program that is first compiled and then
executed
There are two types of scripts
20
Client-side scripting benefits
client-side scripting (JavaScript) benefits:
usability: can modify a page without having to
post back to the server (faster UI)
efficiency: can make small, quick changes to
page without waiting for server
event-driven: can respond to user actions like
clicks and key presses
21
Disadvantages of client-side
scripting
• There is no guarantee that the client has JavaScript
enabled .
22
Server-side scripting benefits
server-side programming (PHP) benefits:
security: has access to server's private data;
client can't see source code
compatibility: not subject to browser
compatibility issues
power: can write files, open connections to
servers, connect to databases, ...
23
Difference between client and server
side scripting
[Link] Server-side Scripting Client-side Scripting
1 It helps work with the back end. It helps work with the front end.
3 It runs on the web server. The scripts are run on the client browser.
5 This is not visible to the client side of the application. It depends on the browser’s version.
It requires the interaction with the server for the data to be It doesn’t interact with the server to process
6
process. data.
Server side scripting requires languages such as PHP, Client side scripting involves languages such
7
[Link], ColdFusion, Python, Ruby on Rails. as HTML, CSS, JavaScript.
It is considered to be a secure way of working with It is considered to be less secure in
8
applications. comparison to client side scripting.
9 It can be used to customize web pages. It helps reduce the load on the server.
24
Script tag in HTML
The HTML <script> tag is used for declaring a
script (such as JavaScript) within your HTML
document.
The <script> tag is used to embed a client-side
script (JavaScript).
The <script> element either contains scripting
statements, or it points to an external script file
through the src attribute.
25
Script tag in HTML
To select an HTML element, JavaScript most often
uses the [Link]() method.
<!DOCTYPE html>
Output:
<html>
<body>
The script element
<h1>The script element</h1>
Hello SRMite!
<p id="demo"></p>
You're visiting Unit-1 first example!
<script>
[Link]("demo").innerHTML = "Hello SRMite!";
[Link]("You're visiting Unit-1 first example!")
</script>
</body>
</html> 26
Popups
Used for displaying information to the user outside of the
page.
Typically as a warning or when an error has occured
Ask user for additional information
Confirmation
alert(<text>); - Exits via an okay button
confirm(<text>); - Returns true or false (ok or cancel)
prompt(<text>, <default>); - Returns user's input
27
Java Script
“ can change the web site
content”
What is JavaScript
JavaScript is the world's most popular scripting
language. (Programming language of the web)
It is
1. object-based,
2. lightweight,
3. cross-platform translated language.
It is widely used for client-side validation.
The JavaScript Translator (embedded in the browser) is
responsible for translating the JS code for the web
browser.
JavaScript is easy to learn.
29
Features of JavaScript
Some of the features of JavaScript are:
Lightweight
Interpreted programming language
Good for the applications which are network-centric
Complementary to Java
Complementary to HTML
Open source
Cross-platform
30
Advantages of JavaScript Disadvantages of JavaScript
Server interaction is less No support for multithreading
Feedback to the visitors is No support for multiprocessing
immediate Reading and writing of files is
Interactivity is high not allowed
Interfaces are richer No support for networking
applications.
31
JavaScript
1. JavaScript Can Change HTML Content
2. JavaScript Can Change HTML Attribute
Values
3. JavaScript Can Change HTML Styles (CSS)
4. JavaScript Can Hide HTML Elements
5. JavaScript Can Show HTML Elements
32
Program 1
<html>
<body>
<h2>Hello world !</h2>
<script>
[Link](“Welcome");
</script>
</body>
</html>
33
Add two numbers
<html>
<body>
<h2>ARITHMETIC OPERATOR</h2>
<script>
a=9;
b=12;
add=a+b;
[Link]("After addition:"+add);
[Link]("<br>");
</script>
</body>
</html> 34
<html>
<body> Add two numbers
<h2>ARITHMETIC OPERATOR</h2>
<script>
a=parseInt([Link]("enter the a value"));
b=parseInt([Link]("enter the b value"));
add=a+b;
[Link]("After addition:"+add);
[Link]("<br>");
</script>
</body>
</html> 35
1. JavaScript Can Change
HTML Content
1. <!DOCTYPE html>
2. <html>
3. <body>
4. <h2>What Can JavaScript Do?</h2>
5. <p id="demo">JavaScript can change HTML content.</p>
6. <button type="button"
onclick='[Link]("demo").innerHTML =
"Hello JavaScript!"'>Click Me!</button>
7. </body>
8. </html>
36
JavaScript Can Change
HTML Attribute Values
1. <!DOCTYPE html> <html> <body>
2. <h2>What Can JavaScript Do?</h2>
3. <p>JavaScript can change HTML attribute
values.</p>
4. <p>In this case JavaScript changes the value of
the src (source) attribute of an image.</p>
5. <button
onclick="[Link]('myImage').
src='pic_bulbon.gif'">Turn on the light</button>
7. <button
onclick="[Link]('myImage').
src='pic_bulboff.gif'">Turn off the light</button>
37
8. </body> </html>
JavaScript Can Change
HTML Styles (CSS)
Changing the style of an HTML element, is a
variant of changing an HTML attribute
1. <!DOCTYPE html> <html>
2. <body>
3. <h2>What Can JavaScript Do?</h2>
5. <button type="button"
onclick="[Link]('demo')
.[Link]='35px'">Click Me!</button>
6. </body>
7. </html> 38
JavaScript Can Hide
HTML Elements
Hiding
HTML elements can be done by
changing the display style
1. <!DOCTYPE html>
2. <html>
3. <body>
4. <h2>What Can JavaScript Do?</h2>
6. <button type="button"
onclick="[Link]('demo').
[Link]='none'">Click Me!</button>
7. </body>
39
8. </html>
JavaScript Can Show
HTML Elements
1. <!DOCTYPE html>
2. <html>
3. <body>
4. <h2>What Can JavaScript Do?</h2>
5. <p>JavaScript can show hidden HTML
elements.</p>
7. <button type="button"
onclick="[Link]('demo')
.[Link]='block'">Click Me!</button>
8. </body>
9. </html> 40
Java Script declaration
JavaScript variables are containers for
storing data values.
In this example, x, y, and z, are variables,
var x = 5;
var y = 6;
var z = x + y;
41
Java Script declaration: Eg
1. <!DOCTYPE html>
2. <html>
3. <body>
4. <h2>JavaScript Variables</h2>
5. <p id="demo"></p>
Output:
6. <script>
7. var price1 = 5; JavaScript Variables
8. var price2 = 6; The total is: 11
9. var total = price1 + price2;
10. [Link]("demo").innerHTML = "The total is: " +
total;
11. </script> Note:JavaScript accepts both
12. </body> </html> double and single quotes:
42
Note:
Old JavaScript examples may use a type
attribute:
<script type="text/javascript">.
43
Output printing
JavaScript can "display" data in different
ways:
1. Writing into an HTML element, using innerHTML
2. Writing into the HTML output, using [Link]()
3. Writing into an alert box, using [Link]()
4. Writing into the browser console, using [Link]()
44
document. Write
1. <!DOCTYPE html>
2. <html>
3. <body>
4. <h2>My First Web Page</h2>
5. <p>My first paragraph.</p>
7. <script>
8. [Link](5 + 6);
9. </script>
10.</body>
11.</html> 45
document. Write
Using [Link]() after an HTML document
is loaded, will delete all existing HTML
1. <!DOCTYPE html>
2. <html>
3. <body>
4. <h2>My First Web Page</h2>
5. <p>My first paragraph.</p>
7. </body> 46
8. </html>
innerHTML
To access an HTML element, JavaScript can
use the [Link](id)
method.
The id attribute defines the HTML element.
6. <p id="demo"></p>
7. <script>
8. [Link]("demo").innerHTML = 5 + 6;
9. </script>
10.</body>
11.</html>
48
window .alert
Use an alert box to display data
Window object is the global scope object
Variables, Properties, and Methods by default
49
window .alert
1. <!DOCTYPE html>
2. <html>
3. <body>
6. <script>
7. [Link](5 + 6); or alert(5 + 6);
8. </script>
9. </body>
10. </html>
50
[Link]
For debugging purposes, the [Link]()
method in the browser to display data. Web Page content
1. <!DOCTYPE html> Activate Debugging
2. <html> F12 on your keybord will activate debugging.
3. <body> Then select "Console" in the debugger menu.
4. <h2>Activate Debugging</h2> Then click Run again.
5. <p>F12 on your keybord will activate debugging.</p>
6. <p>Then select "Console" in the debugger menu.</p> Debugger Menu
7. <p>Then click Run again.</p>
8. <script>
9. [Link](5 + 6);
10. </script>
11. </body>
12. </html>
51
JavaScript Print
JavaScript does not have any print object or
print methods.
Cannot access output devices from
JavaScript.
The only exception is that you can call the
52
JavaScript Print
1. <!DOCTYPE html>
2. <html>
3. <body>
4. <h2>The [Link]()
Method</h2>
6. <button
onclick="[Link]()">Print
this page</button>
7. </body>
8. </html>
53
JavaScript Programs
A computer program is a list of
"instructions” to be "executed" by a
computer.
In a programming language, these
programming statements.
In HTML, JavaScript programs are
[Link]("demo").innerHTML =
"Hello Dolly!";
58
JavaScript Literals
Thetwo most important syntax rules for fixed
values are:
1. Numbers are written with or without decimals:
10.50
1001
'John Doe'
59
JavaScript Variables
In a programming language, variables are used
to store data values.
JavaScript uses the var keyword to declare variables.
It's a good programming practice to declare all variables
at the beginning of a script.
An equal sign is used to assign values to variables.
var x;
x = 6;
60
JavaScript Identifiers
All JavaScript variables must be identified with unique names.
These unique names are called identifiers.
Identifiers can be short names (like x and y) or more descriptive
names (age, sum, totalVolume).
The general rules for constructing names for variables (unique
identifiers) are:
1. Names can contain letters, digits, underscores, and dollar signs.
2. Names must begin with a letter
3. Names can also begin with $ and _
4. Names are case sensitive (y and Y are different variables)
5. Reserved words (like JavaScript keywords) cannot be used as names
Used to name variables (and keywords, and functions, and labels). 61
Comments
Not all JavaScript statements are "executed".
Code after double slashes // or between /* and */ is treated as
a comment.
Comments are ignored, and will not be executed
Two categories
1. Single Line Comments //
// Change heading:
[Link]("myH").innerHTML = "My First Page";
// Change paragraph:
[Link]("myP").innerHTML = "My first paragraph.";
2. Multi-line Comments (a comment block) /* and */
/*
The code below will change
the heading with id = "myH“
*/
62
[Link]("myH").innerHTML = "My First Page";
Unit 1
Need of Scripting Language, Difference between client and server side scripting, Script tag
in HTML, Java Script declaration, Output printing – document. Write, innerHTML,
window .alert, [Link], Java script statements, Comments and Variables,
Lab 1 – Java Script Input and Output
Java script Operators -Logical, Bitwise, Arithmetic and Assignment operators, Java Script
Datatypes – numeric, Java Script Datatypes – non numeric, Conditional statements, If else
statements, Switch statements, Iteration statements,
Lab 2 – Java Script Operators and Conditions
Loop Controls – for loop, While loop, Do while Loop, For each loop, Arrays , Introduction and
declaring, Accessing arrays, Array Properties : index, input length, prototype, Array
Methods :concat, every, forEach,
Lab 3 - Looping Statements
Operators
The numbers (in an arithmetic operation) are called operands.
The operation (to be performed between the two operands) is
defined by an operator.
11 == Equal x == y
11 === Strict equal x === y
11 != Unequal x != y
11 !== Strict unequal x !== y
10 & Bitwise AND x&y
9 ^ Bitwise XOR x^y
8 | Bitwise OR x|y
7 && Logical AND x && y
6 || Logical OR x || y
5 ?? Nullish Coalescing x ?? y
4 ?: Condition ? "Yes" : "No"
66
Value Operator Description Example
3 += Assignment x += y
3 /= Assignment x /= y
3 -= Assignment x -= y
3 *= Assignment x *= y
3 %= Assignment x %= y
3 <<= Assignment x <<= y
3 >>= Assignment x >>= y
3 >>>= Assignment x >>>= y
3 &= Assignment x &= y
3 ^= Assignment x ^= y
3 |= Assignment x |= y
2 yield Pause Function yield x
1 , Comma 5,6 67
Java script Operators -Logical,
Bitwise
Comparison and Logical operators are used to
test for true or false.
Operator Description Comparing Returns
x == 8 FALSE
x == 5 TRUE
== equal to
x == "5" TRUE
x === 5 TRUE
=== equal value and equal type x === "5" FALSE
x !== 5 FALSE
not equal value or not equal x !== "5" TRUE
!==
type
x !== 8 TRUE
x <= 8 TRUE 68
<= less than or equal to
Java script Operators - Bitwise
Bit operators work on 32 bits numbers.
Any numeric operand in the operation is converted into a 32 bit number.
Zero fill right Shifts right by pushing zeros in from the left,
>>> 69
shift and let the rightmost bits fall off
Java script Operators - Bitwise
JavaScript stores numbers as 64 bits floating point numbers, but all bitwise
operations are performed on 32 bits binary numbers.
Before a bitwise operation is performed, JavaScript converts numbers to 32
bits signed integers.
After the bitwise operation is performed, the result is converted back to 64
bits JavaScript numbers.
<!DOCTYPE html>
<html>
Deci
mal
Binary <body>
<h2>JavaScript Bitwise AND</h2>
5 00000000000000000000000000000101 <p id="demo">My First Paragraph.</p>
1 00000000000000000000000000000001 <script>
[Link]("demo").innerHTML = 5 & 1;
5& 00000000000000000000000000000001 </script>
1 (1)
</body>
</html> 70
Java script Operators - Arithmetic
Arithmeticoperators perform arithmetic on
numbers (literals or variables).
Operator Description
+ Addition
- Subtraction
* Multiplication
** Exponentiation (ES2016)
/ Division
% Modulus (Remainder)
++ Increment
-- Decrement
71
Java script Operators - Assignment
Value Operator Description Example
3 += Assignment x += y
3 /= Assignment x /= y
3 -= Assignment x -= y
3 *= Assignment x *= y
3 %= Assignment x %= y
3 <<= Assignment x <<= y
3 >>= Assignment x >>= y
3 >>>= Assignment x >>>= y
3 &= Assignment x &= y
3 ^= Assignment x ^= y
3 |= Assignment x |= y
2 yield Pause Function yield x
1 , Comma 5,6
72
Java Script Datatypes
JavaScript variables can hold many data types:
numbers, strings, objects and more
JavaScript has dynamic types. This means that the
same variable can be used to hold different data types
To be able to operate on variables.
Without data types, a computer cannot safely solve any
expressions
Two classifications
1. Primitive types
2. Complex types
73
1. Primitive types
A primitive data value is a single simple data value with no
additional properties and methods.
i. string typeof "John" // Returns "string"
ii. number typeof 3.14 // Returns "number"
typeof true // Returns "boolean"
iii. boolean typeof false // Returns "boolean"
iv. Undefined typeof x // Returns "undefined" (if x has no value)
2. Complex types
The typeof operator returns "object" for objects, arrays, and null.
The typeof operator does not return "object" for functions.
75
1. Infinity
Infinity represents the mathematical Infinity ∞.
It is a special value that’s greater than any
number.
1. We can get it as a result of division by zero:
alert( 1 / 0 ); // Infinity
76
2. NaN
NaN represents a computational error.
1. It is a result of an incorrect or an undefined
mathematical operation, for instance:
alert( "not a number" / 2 ); // NaN, such division is erroneous
77
3. BigInt
The “number” type cannot represent integer values
80
Java Script Datatypes – non numeric
2. Boolean
The boolean type has only two values: true and false.
This type is commonly used to store yes/no values: true means
“yes, correct”, and false means “no, incorrect”.
All other types are called “primitive” because their values can contain
only a single thing (be it a string or a number or whatever). In contrast,
objects are used to store collections of data and more complex entities.
85
If statements
UseIf statement if you want to check only a
specific condition
Syntax:
if (condition)
{
lines of code to be executed if condition is
true
}
86
If statements
<html>
<head>
<title>IF Statments!!!</title>
<script type="text/javascript">
var age = prompt("Please enter your age");
You are an adult
if(age>=18)
[Link]("You are an adult <br />");
if(age<18)
[Link]("You are NOT an adult <br />");
</script>
</head>
<body>
</body>
</html>
87
If else statements
If….Else
statement checks two conditions
and execute a different set of codes.
Syntax:
if (condition)
{
lines of code to be executed if the condition
is true
}
else
{
lines of code to be executed if the condition
is false
} 88
If else statements
<html>
<head>
<title>If...Else Statments!!!</title>
<script type="text/javascript">
// Get the current hours Good Afternoon!!!
var hours = new Date().getHours();
if(hours<12)
[Link]("Good Morning!!!<br />");
else
[Link]("Good Afternoon!!!<br />");
</script>
</head>
<body>
</body>
</html>
89
If…Else If…Else statement
Check more than two conditions
Syntax:
if (condition1)
{
lines of code to be executed if condition1 is true
}
else if(condition2)
{
lines of code to be executed if condition2 is true
}
Else
{
lines of code to be executed if both condition1
and condition2 are false 90
}
If…Else If…Else statement
<html>
<head>
<script type="text/javascript">
var one = prompt("Enter the first number");
var two = prompt("Enter the second number");
one = parseInt(one);
two = parseInt(two);
if (one == two)
[Link](one + " is equal to " + two + ".");
else if (one<two)
[Link](one + " is less than " + two + ".");
else
[Link](one + " is greater than " + two + ".");
20 is less than 40.
</script>
</head>
<body>
</body>
</html> 91
Switch statements
Select one of many code blocks to be executed
Syntax:
switch(expression)
{
case x:
// code block
break;
case y:
// code block
break;
default:
// code block
}
95
Loop Controls – for loop
Syntax Example
96
Loop Controls – for in
Syntax Example
for (key in object) var person = {fname:"John", lname:"Doe", age:25};
{ var text = "";
// code block to be executed var x;
} for (x in person) { text += person[x]; }
The for in loop iterates over a person object
Each iteration returns a key (x)
The key is used to access the value of the key
The value of the key is person[x]
Syntax Example
If you forget to increase the variable used in the condition, the loop will never end.
101
This will crash your browser.
Do while Loop
A variant of the while loop.
This loop will execute the code block once, before checking if the
condition is true, then it will repeat the loop as long as the condition
is true.
Syntax Example
do do
{ {
// code block to be executed text += "The number is " + i;
} i++;
while (condition); }
while (i < 10);
Important Note:
If you forget to increase the variable used in the condition, the loop will never end.
102
This will crash your browser.
What is an Array
Arrays are complex variables.
Store more than one value or a group of values under a
single variable name.
Can store any valid value
strings,
numbers,
objects,
functions,
other arrays
Possible to create more complex data structures such as
an array of objects or an array of arrays
103
Arrays declaration/Creating an Array
An ordered structure for storing multiple values or a group of values
Enclosing a comma-separated list of values in square brackets ([])
Using Array literal
var myArray = [element0, element1, ..., elementN];
106
[Link] New - beginning of an array
Toadd a new element at the beginning of an
array use the unshift() method
107
[Link] New - end of an array
Toadd a new element at the end of an array,
simply use the push() method
108
[Link] - Multiple elements at once in
an array
To add multiple elements at once using
the push() and unshift() methods
111
Methods and Techniques - Removing
Elements from an Array
Removing elements using 6 functions
1. pop - Removes from the End of an Array
var ar = [1, 2, 3, 4, 5, 6];
[Link](); // returns 6
[Link]( ar ); // [1, 2, 3, 4, 5]
2. shift - Removes from the beginning of an Array
var ar = ['zero', 'one', 'two', 'three'];
[Link](); // returns "zero"
[Link]( ar ); // ["one", "two", "three"]
112
Methods and Techniques - Removing
Elements from an Array
Removing elements using 6 functions
3. splice - removes from a specific Array index
var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
var removed = [Link](2,2);
[Link]( arr ); //[1, 2, 5, 6, 7, 8, 9, 0]
}
Array Properties : indexof
The indexOf() method searches the array for the specified item, and
returns its position.
Returns the position of the first occurrence if the item is found.
Returns -1 if the item is not found.
Syntax
[Link](item, start)
Syntax
[Link](item, start)
}
Looping Through Array Elements
var fruits = ["Apple", "Banana", "Mango", "Orange", "Papaya"];
[Link]([Link]); // Prints: 5
123
Array Properties : prototype
Note: [Link] does not refer to a single array,
but to the Array() object itself.
Note: Prototype is a global object constructor which is
available for all JavaScript objects.
Make a new array method that transforms array values into upper case
[Link] = function() {
for (i = 0; i < [Link]; i++) {
this[i] = this[i].toUpperCase();
}
};
127
Array Methods : every
<!DOCTYPE html> <html> <body>
<p>Click the button to check if every element in the array has a value above a
specific number.</p>
<p>Minimum age: <input type="number" id="ageToCheck" value="18"></p>
<button onclick="myFunction()">Try it</button>
<p>All ages above minimum? <span id="demo"></span></p>
<script>
var ages = [32, 33, 12, 40];
function checkAdult(age) {
return age >= [Link]("ageToCheck").value;
}
function myFunction() {
[Link]("demo").innerHTML = [Link](checkAdult);
}
</script> </body> </html>
128
Array Methods : every
<script>
var survey = [
{ name: "Steve", answer: "Yes"},
{ name: "Jessica", answer: "Yes"},
{ name: "Peter", answer: "Yes"},
{ name: "Elaine", answer: "No"}
];
function isSameAnswer(el, index, arr) {
if (index === 0){
return true;
} else {
return ([Link] === arr[index - 1].answer);
}
}
function myFunction() {
[Link]("demo").innerHTML = [Link](isSameAnswer);
}
129
</script>
Array Methods :forEach
forEach() method calls a function (a callback function)
once for each array element.
<!DOCTYPE html>
<html> <body> JavaScript
[Link]()
Calls a function once
<h2>JavaScript [Link]()</h2>
for each array element.
<p>Calls a function once for each array element.</p>
45
<p id="demo"></p>
4
9
<script> 16
const numbers = [45, 4, 9, 16, 25]; 25
let txt = "";
[Link](myFunction);
[Link]("demo").innerHTML = txt;
function myFunction(value, index, array) { txt += value + "<br>"; } 130
132
133
134
135
136