Web Programming Complete Notes
Web Programming Complete Notes
WWW can be defined as the collection of different websites around the world, containing different
information shared via local servers(or computers).
Working of WWW:
The World Wide Web is based on several different technologies: Web browsers, Hypertext Markup
Language (HTML), and Hypertext Transfer Protocol (HTTP).
A Web browser is used to access web pages. Web browsers are programs that display text, data,
pictures, animation, and video on the Internet. Hyperlinked resources on the World Wide Web can be
accessed using software interfaces provided by Web browsers. Initially, Web browsers were used only
for surfing the Web but now they have become more universal. Web browsers can be used for several
tasks including conducting searches, mailing, transferring files, and much more. Some of the
commonly used browsers are Internet Explorer, Opera Mini, and Google Chrome.
Features of WWW:
Cross-Platform
Distributed
“Web 2.0”
1. Uniform Resource Locator (URL): serves as a system for resources on the web.
Web Basics
Hyperlinks
Hyperlinks in HTML are used to create clickable links that allow users to navigate between
different web pages or sections within the same page. In HTML, hyperlinks are created using the
<a> (anchor) element. The basic syntax for creating a hyperlink is as follows:
The href attribute specifies the destination URL that the link should point to. It can be an
absolute URL (e.g., "https://www.example.com") or a relative URL (e.g., "page.html").
The link text is the visible text that users can click on. It goes between the opening and
closing <a> tags.
Eg:
In this example, the link text is "Visit Example Website," and when users click on it, they will be
directed to the URL "https://www.example.com".
https://youtu.be/vpYct2npKD8
URI, URL, and URN are all related terms used in the context of identifying and locating resources
on the internet. Here's what they stand for:
URI: URI stands for Uniform Resource Identifier. It is a string of characters used to identify and
locate a resource. A URI can be further classified into two types: URLs and URNs.
URL: URL stands for Uniform Resource Locator. It is a specific type of URI that provides the
means to access a resource on the internet. A URL typically consists of several components,
including the protocol (such as "http" or "https"), the domain name or IP address of the server, and
URN: URN stands for Uniform Resource Name. It is another type of URI that is used to identify a
resource by its name or identifier rather than by its location. URNs are persistent and unique,
allowing resources to be identified even if they are moved or renamed. However, unlike URLs,
URNs do not provide a means to directly access the resource. An example of a URN is
"urn:isbn:0451450523," which identifies a book by its ISBN number.
Parts of URL
A URL (Uniform Resource Locator) is a string of characters that provides the address of a
resource on the internet. Let's break down the components of a URL based on the information
you provided:
1. Protocol: The protocol is indicated at the beginning of the URL and specifies the method
to be used for accessing the resource. In this case, "http://" indicates the use of the HTTP
(HyperText Transfer Protocol) for retrieving the resource. Other protocols include
"https://" for secure HTTP, "ftp://" for File Transfer Protocol, and so on.
2. Hostname: The hostname identifies the web server computer on which the resource is
located. In your example, the hostname is "www.deitel.com." The hostname is a part of
the fully qualified domain name (FQDN) and is used to uniquely identify the server. The
FQDN typically consists of a combination of the hostname and the domain name (e.g.,
"www" is the hostname, and "deitel.com" is the domain name).
The web browser sends an HTTP request to the server. The request (in its simplest form) is:
The word GET is an HTTP method indicating that the client wishes to obtain a resource from
the server. The remainder of the request provides the path name of the resource (e.g., an
HTML5 document) and the protocol’s name and version number (HTTP/1.1). The client’s
request also contains some required and optional headers. Any server that understands HTTP
(version 1.1) can translate this request and respond appropriately.
The server first sends a line of text that indicates the HTTP version, followed by a numeric
code and a phrase describing the status of the transaction.
Eg:
HTTP/1.1 200 OK
informs the client that the web server could not locate the requested resource.
HTTP Headers
The server sends one or more HTTP headers, which provide additional information about the data
that will be sent. In this case, the server is sending an HTML5 text document, so one HTTP header
for this example would read:
Content-type: text/html
The information provided in this header specifies the Multipurpose Internet Mail Extensions
(MIME) type of content that the server is transmitting to the browser. The MIME standard
specifies data formats, which programs can use to interpret data correctly.
Eg:
The MIME type text/plain indicates that the sent information is text that can be displayed directly.
Similarly, the MIME type image/jpeg indicates that the content is a JPEG image.
When a client sends a GET request, it is asking the server to retrieve a specific
resource identified by a URL (Uniform Resource Locator).
The parameters and data associated with a GET request are appended to the URL as
query parameters.
GET requests are typically used for retrieving data, and they are considered safe and
idempotent, meaning they should not have any side effects on the server.
2. POST request:
The POST method is used to send data to the server to create or update a resource.
Unlike GET requests, the data sent in a POST request is not appended to the URL but
is included in the body of the request.
POST requests are commonly used for submitting forms, uploading files, or
performing any action that modifies data on the server.
Client-side Caching
Client-side caching is a mechanism employed by web browsers to store and reuse recently
viewed web pages, resulting in quicker page reloading. When a browser retrieves a web page,
it can cache the content locally and refer to it for subsequent requests, avoiding the need to
fetch the data again from the server. The browser determines the freshness of the cached
content based on the HTTP response headers, such as "Cache-Control" or "Expires," which
specify the duration the content remains fresh.
HTTP is a request-response protocol. The client sends a request to the server, and the server sends a
response back to the client. The request and response messages are made up of a series of headers and
a body. The headers contain information about the request or response, such as the type of request, the
length of the body, and the encoding of the body. The body contains the actual data that is being
transferred.
Introduction to HTML
Origins and Evolution of HTML
HTML Origins
The goal was to create a way to share information across different computers.
HTML was originally designed to be used with the NeXTSTEP operating system.
HTML Evolution
HTML has evolved over time to add new features and improve the way it works.
HTML 2.0 (1994): Added support for tables, forms, and images.
HTML 3.2 (1996): Added support for multimedia, frames, and style sheets.
HTML 4.01 (1999): Added support for internationalization, accessibility, and improved
semantics.
HTML5 (2014): The latest major version of HTML. It adds support for new features such as
video, audio, and canvas elements.
HTML Today
HTML is a powerful tool that can be used to create a wide variety of web pages, from simple text
pages to complex interactive applications.
<!DOCTYPE html>
<html>
<head>
<title>My First HTML Document</title>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
This document will create a web page with a heading and a paragraph. The heading will be displayed
in large, bold text, and the paragraph will be displayed in normal text.
<!DOCTYPE html>
<html>
<head>
<title>Document Title</title>
</head>
<body>
<!-- Page Content -->
</body>
</html>
The <!DOCTYPE html> declaration tells the browser that this document is an HTML5 document.
The <html> element is the root element of an HTML document. It contains the <head> and <body>
elements.
The <head> element contains meta-information about the document, such as the title and the character
set.
The <title> element specifies the title of the document. It is displayed in the browser's title bar.
The <body> element contains the main content of the document. It can contain headings, paragraphs,
images, tables, forms, and other elements.
unordered List
An ordered list represents a list of items in a specific order, typically displayed with numbers or
letters. Each list item is wrapped in <li> tags.
Example:
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
ordered List
An unordered list represents a list of items without any particular order, typically displayed with bullet
points. Each list item is wrapped in <li> tags.
Example:
<ol>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ol>
Definition List
A definition list represents a list of terms and their corresponding definitions. Each term is wrapped in
<dt> tags, and each definition is wrapped in <dd> tags.
Example:
Tables
In HTML, tables are used to display tabular data in a structured format. Tables consist of rows ( <tr> )
and columns ( <td> or <th> ). The <td> element represents a standard cell within a table, while the
<th> element represents a header cell. Here's an example of how to create a basic HTML table:
<table>
<tr>
<th>header 1</th>
<th>header 2</th>
<th>header 3</th>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
</tr>
<tr>
<td>Data 4</td>
<td>Data 5</td>
<td>Data 6</td>
</tr>
</table>
<!DOCTYPE html>
<html>
<head>
<head>
<title>Ima400ge </title>
<img src="path/to/image.jpg" alt ="Windows wallpaper" ,width ="400px" height="300px">
</head>
</head>
</html>
Hypertext Links
Hypertext is a method of organizing and presenting information in which text is linked together
through hyperlinks. It allows users to navigate between different pieces of text or information by
clicking on links within a document or web page
<!DOCTYPE html>
<html>
<head>
<title>Hypertext Links</title>
</head>
<body>
<h1>HyperLinks</h1>
<a href="http://itanimulli.com">click Here</a>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Forms</title>
</head>
<body>
<h1>Forms Example</h1>
<form>
<label for ="name">Name:</label>
<input type="text" id="name" name="name" required>
<label for="message">Message:</label>
<textarea id="message" name="message" rows="4" cols="30"></textarea>
</form>
</body>
</html>
output
<input> tags with different types ( type="text" , type="email" ) for text input and email input
fields.
<textarea> tag for multi-line text input, which is useful for longer messages or comments.
<input> tags with type="submit" and type="reset" for the submit and reset buttons,
respectively.
The name attribute is used to identify each input field, and the id attribute is used to associate labels
with their corresponding input elements.
When the form is submitted, the data is sent to the server for processing. The server-side code,
typically written in a language like PHP, Python, or JavaScript, receives the form data and can
perform actions like storing it in a database or sending an email.
Remember to adjust the action attribute of the <form> tag to the appropriate URL or script that will
handle the form submission on your server.
Frames
Frames were an HTML feature that allowed web developers to divide a web page into multiple
sections, each containing its own independent HTML document or webpage.
<!DOCTYPE html>
<html>
<head>
<title> Frame Example </title>
</head>
<frameset cols="25%,75%">
<frame src="menu.html" name="menu">
<frame src="content.html" name="content">
</frameset>
</html>
Note: It is called a Logical structure because DOM doesn’t specify any relationship
between objects.
Form Control Elements:: Form can have many control elements such as text fields,
buttons, radio buttons, checkboxes, etc.
Elements like nav, and header A new element for web structure
were not present. like nav, header, footer, etc.
Examples of semantic elements: <form> , <table> , and <article> - Clearly defines its
content.
- <article>
- <aside>
- <details>
- <figcaption>
- <figure>
- <footer>
- <header>
- <main>
- <mark>
- <nav>
- <section>
- <summary>
- <time>
Chapters
Introduction
News items
Contact information
A web page could normally be split into sections for introduction, content, and contact
information.
Eg:
Forum posts
Blog posts
User comments
Product cards
Newspaper articles
Eg:
logo or icon
authorship information
Note: You can have several <header> elements in one HTML document
.However, <header> cannot be placed within a <footer> , <address> or another <header> element.
Eg:
authorship information
copyright information
contact information
sitemap
related documents
Eg:
An article should make sense on its own and it should be possible to distribute it
independently from the rest of the site.
Forum post
Blog post
Figure tag
The <figure> tag specifies self-contained content, like illustrations, diagrams, photos,
code listings, etc.
Header tag
The <header> tag is an HTML element used to define a header section of a document or a
specific section within a document. It is typically used to contain introductory
content, branding elements, navigation menus, or other top-level content on a webpage.
Hgroup tag
The <hgroup> element is used to group multiple heading elements ( <h1> to <h6> ) as a
single heading, typically for styling or presentation purposes. However, due to its
limited browser support and lack of standardized behavior, it is generally recommended
to use individual heading elements to represent the document structure instead.
The <footer> element is commonly used to provide important information and navigation
links at the bottom of a webpage. It helps to separate the footer content from the main
content and header sections, providing a clear visual distinction.
Navigation tag
The <nav> tag is an HTML element used to define a section of a document that contains
navigation links. It is specifically intended for structural navigation blocks, such as
menus, lists of links, or other types of navigation elements.
Aside tag
The <aside> tag is an HTML element used to mark content that is tangentially related to
the main content of a webpage. It is typically used to enclose content such as
sidebars, pull quotes, author information, related links, or any other content that is
considered separate from the main content but still related or supportive.
HTML5 Canvas
The HTML <canvas> element is used to draw graphics on a web page.
The graphic to the left is created with <canvas> . It shows four elements: a red
rectangle, a gradient rectangle, a multicolor rectangle, and a multicolor text.
CSS works by selecting HTML elements and applying specific styles to them. These styles
can be defined directly within an HTML document using the <style> tag, or they can be
stored in separate CSS files and linked to the HTML document using the <link> tag.
To use an external style sheet, add a link to it in the <head> section of each HTML
page:
The following example sets the text color of ALL the <h1> elements
(on that page) to blue, and the text color of ALL the <p> elements to
red. In addition, the page will be displayed with a "powderblue" background
color:
Selector Forms
A CSS selector is the first part of a CSS Rule. It is a pattern of elements and other
terms that tell the browser which HTML elements should be selected to have the CSS
property values inside the rule applied to them. The element or elements which are
selected by the selector are referred to as the subject of the selector.
Types of selectors :
Element Selectors
ID Selectors
The id selector selects the id attribute of an HTML element to select a specific
element. An id is always unique within the page so it is chosen to select a single,
unique element.
It is written with the hash character (#), followed by the id of the element.
Class Selectors
The .class selector selects elements with a specific class attribute.
To select elements with a specific class, write a period (.) character, followed by
the name of the class.
Group Selectors
The grouping selector is used to select all the elements with the same style
definitions. Grouping selector is used to minimize the code. Commas are used to
separate each selector in grouping.
color: black;
1. color: value; - Specifies the text color of an element. The value can be a named color
(e.g., red , blue ), a hexadecimal color code (e.g., #ff0000 ), or an RGB/RGBA value
(e.g., rgb(255, 0, 0) ).
2. - Sets the size of the font used within an element. The value can be
font-size: value;
6. - Sets the margin (space) around an element. The value can be specified
margin: value;
in pixels, percentages, or other units. You can use shorthand notations like margin-
top , margin-right , margin-bottom , and margin-left to define individual margins.
7. padding: value; - Defines the padding (space) within an element. The value can be
specified in pixels, percentages, or other units. Like margins, you can use
shorthand notations ( padding-top , padding-right , padding-bottom , and padding-left ) to specify
individual paddings.
8. border: value; - Specifies the border properties of an element. The value can include
properties like border-width, border-style, and border-color. For example: border: 1px
solid black; .
Font properties
CSS Font property is used to control the look of texts. By the use of CSS font property
you can change the text size, color, style and more. You have already studied how to
make text bold or underlined. Here, you will also know how to resize your font using
percentage.
Some of the font properties are:
By a color name
By hexadecimal value
By RGB
400 has the same weight as normal, and 700 have the same as bold.
CSS Font-Variant
The font-variant property in CSS allows you to transform the specific line of text or
paragraph into small caps (capital letters that will be small in size as compared to
normal capital letters).
It can also have values such as normal (by default), initial- This sets the property
to the default value, and inherit- It takes the property's value of the parent
element to the child element.
In CSS, we use the font-family property to specify the family/ genre of the font on
the webpage.
Cursive – similar to human cursive writing, the letters are partially or fully
connected.
font-family: family-name|generic-family|initial;
line-height: normal|number|length|percentage|initial;
Variables are used to store data values in JavaScript. You can declare a variable using the var ,
let or const keyword.
1. var : Prior to the ES6 (ECMAScript 2015) standard, the var keyword was used to declare
variables. Variables declared with var have function scope or global scope, depending on
where they are declared. For example:
2. let : Introduced in ES6, the let keyword allows you to declare block-scoped variables.
Variables declared with let are limited to the block (enclosed by curly braces) in which they
are defined. They can be reassigned later within the same block. For example:
3. const : Also introduced in ES6, the const keyword is used to declare variables that have a
constant value. Once a value is assigned to a const variable, it cannot be reassigned. const
variables are block-scoped as well. For example:
const PI = 3.14159;
note that variables declared with let and const have block scope, whereas variables declared
with var have function or global scope. Block scope refers to variables being accessible only within
the block they are defined in (e.g., inside a loop or an if statement).
Example
if (x === 5) {
let y = 20; // y is a different variable in this block
const z = 25; // z is a different variable in this block
console.log(x, y, z); // Output: 5 20 25
}
In this example, the if statement creates a new block scope, and the variables y and z defined
within the block are separate from the outer variables with the same names.
Data-types
Primitive Data Types
Number: Represents numeric values, including integers and floating-point numbers. For
example: let age = 25;
Boolean: Represents a logical value, either true or false . For example: let isStudent =
true;
Null: Represents the intentional absence of any object value. For example: let myVariable =
null;
Symbol: Represents a unique identifier. Symbols are often used as keys in objects to avoid
naming conflicts. For example: let id = Symbol("unique");
let person = {
name: "John",
age: 25,
isStudent: true
};
Array: Represents an ordered list of values, enclosed in square brackets. Arrays can
contain elements of any data type. For example:
Assignment operators are used to assign values to variables. For example, the assignment
operator (=) assigns the value of the expression on the right side of the operator to the variable
on the left side.
Comparison operators are used to compare two values and determine if they are equal,
greater than, less than, or not equal. For example, the equal to operator (==) compares two
values and returns true if they are equal, and false if they are not.
Logical operators are used to combine logical expressions. For example, the logical AND
operator (&&) returns true if both of the expressions it is applied to are true, and false if either
of them is false.
Bitwise operators are used to perform bitwise operations on numbers. For example, the
bitwise AND operator (&) performs a Boolean AND operation on each bit of its integer
arguments.
Subtraction -
Multiplication *
Division /
Modulus %
Addition assignment +=
Subtraction assignment -=
Multiplication assignment *=
Division assignment /=
Modulus assignment %=
Not equal to !=
Logical OR ||
Logical NOT !
Bitwise OR |
Bitwise XOR ^
Bitwise NOT ~
Control Structure
Conditional statements
if Statement
The if statement is used to execute a block of code if a certain condition is true. It has the
following syntax:
if (condition) {
// Code to be executed if the condition is true
} else {
// Code to be executed if the condition is false
}
Example:
if (num > 0) {
console.log("The number is positive.");
} else {
console.log("The number is non-positive.");
}
//Output: The number is positive.
Ternary Statement
The ternary operator provides a more concise way to write conditional statements. It is a
shorthand form of an if-else statement. The syntax of the ternary operator is as follows:
Example:
let num = 5;
let result = num > 0 ? "Positive" : "Negative or zero";
Loop statements
switch Statement
The switch statement allows you to select one of many code blocks to be executed based
on the value of an expression. It has the following syntax:
switch (expression) {
case value1:
// Code to be executed if the expression matches value1
break;
case value2:
// Code to be executed if the expression matches value2
break;
// More cases...
default:
// Code to be executed if none of the cases match
break;
}
Example:
switch (day) {
case "Monday":
console.log("It's the beginning of the week.");
break;
case "Friday":
console.log("It's the end of the week.");
break;
default:
console.log("It's another day of the week.");
break;
}
//Output: It's the beginning of the week.
for Loop
The for loop is used to repeat a block of code for a specified number of times. It has the
following syntax:
Example:
while Loop
The while loop is used to repeat a block of code as long as a condition is true. It has the
following syntax:
while (condition) {
// Code to be executed in each iteration
}
Example:
let count = 0;
//Output:
//Count: 0
//Count: 1
//Count: 2
//Count: 3
//Count: 4
Do-while Loop
The do-while loop is similar to the while loop, but it always executes the block of code at
least once before checking the condition. It has the following syntax:
do {
// Code to be executed in each iteration
} while (condition);
Example:
let i = 0;
do {
console.log(i);
i++;
} while (i < 5);
//Output:
//0
//1
Functions
Functions are reusable blocks of code that perform a specific task or calculate a value. They play a
crucial role in structuring and organizing code, promoting reusability and modularity. Here's an
overview of functions in JavaScript, including function definition, types, function calls, and return
values.
Function Definition
A function in JavaScript is defined using the function keyword, followed by the function name,
a pair of parentheses () , and a block of code enclosed in curly braces {} . The basic syntax
for defining a function is as follows:
Example:
Function Calls
To execute a function, you need to call it by its name, followed by a pair of parentheses () . If
the function has parameters, you can pass the values inside the parentheses.
Example
function greet(name) {
console.log("Hello, " + name + "!");
}
return values
Functions can return values using the return statement. The return statement stops the
execution of the function and sends a value back to the caller.
Function Types
In JavaScript, there are two main types of functions: named functions and anonymous functions
(also known as function expressions).
Named Functions
Named functions are defined with a specific name and can be called by their name. They
are commonly used when you want to reuse the same code block in multiple places within
your program.
Example
function greet(name) {
console.log("Hello, " + name + "!");
}
Anonymous Functions
Anonymous functions, as the name suggests, do not have a specified name. They are often
assigned to variables or used as callback functions.
Example
Pop up Boxes
we can use pop-up boxes to interact with the user by displaying messages or prompts. There are
three main types of pop-up boxes: alert, confirm, and prompt. These boxes provide a way to
communicate with the user and gather input if needed.
Alert Boxes
The alert box displays a message to the user and only requires an acknowledgement from
them. It has a simple OK button to dismiss the box. Here's the syntax to use an alert box:
Confirm Boxes
The confirm box allows the user to confirm or cancel an action. It displays a message along with
two buttons: OK and Cancel. The confirm box returns a Boolean value ( true if OK is clicked,
false if Cancel is clicked). Here's an example:
let result = confirm("Are you sure you want to delete this item?");
if (result) {
// Code to delete the item
} else {
// Code to cancel the deletion
}
The user's choice is stored in the result variable, which can be used to perform different
actions based on the selection.
Prompt Boxes
The prompt box allows the user to input data by providing a text input field along with a
message. It returns the value entered by the user as a string. Here's an example:
In this example, the user will see a prompt box asking them to enter their name. The value
entered by the user will be stored in the name variable, which can be used for further
processing.
Advanced JavaScript
JavaScript Arrays
An array is a special kind of object that can store a collection of data. Arrays are zero-indexed, which
means that the first element of an array is at index 0, the second element is at index 1, and so on.
Once an array is declared, you can access its elements using their indexes. For example, to access
the first element of the fruits array, you would use the following code:
Array Looping
Objects
Objects are one of the fundamental data types and are used to store collections of key-value pairs.
They are versatile and can represent various entities, such as real-world objects, data structures, and
more.
Creating Objects:
There are a few ways to create objects in JavaScript:
1. Object Literal:
const person = {
name: 'John',
age: 25,
profession: 'Engineer'
};
person.age = 30;
person['profession'] = 'Developer';
You can add new properties to an existing object or delete existing properties:
Object Methods:
Objects can also have methods, which are functions attached to the object. These methods can
perform operations on the object's properties or provide additional functionality:
const person = {
name: 'John',
age: 25,
greet: function() {
console.log('Hello, my name is ' + this.name);
}
};
Number Object
The Number object is a built-in object that provides functionality and methods for working with
numbers. It is also used to create instances of numbers as objects.
When you create a Number object using the new Number(value) syntax, you are creating a new
instance of the Number object. The value parameter represents the numeric value that you want to
assign to the Number object.
The Number object has various properties and methods that allow you to perform operations on
numbers. Some commonly used properties include:
Example
In addition to properties, the Number object also provides methods for performing operations on
numbers. Some commonly used methods include toFixed() , toPrecision() , and toString() . These
methods allow you to format numbers and convert them to strings in different ways.
String Object
A string object in JavaScript is a sequence of characters that can be manipulated using a variety of
methods and properties. Strings are immutable, which means that they cannot be changed once
they are created.
You can also use the String() constructor to create a string object:
Date Object
Date object is used to work with dates and times. It provides methods for creating, manipulating,
and formatting dates.
Creating a Date object is done using the new Date() constructor. There are several ways to create a
Date object:
1. Without any arguments: This creates a Date object representing the current dateand time.
2. With a specific date and time: You can pass in the year, month (0-11), day, hour, minute,
second, and millisecond as arguments to specify a particular date and time.
let specificDate = new Date(2023, 6, 10, 12, 30, 0, 0); // July 10, 2023, 12:30:00
4. getDay() : Returns the day of the week (0-6, where 0 is Sunday) of the date.
5. getHours(), getMinutes() , getSeconds() : Return the hour, minute, and second of the date,
respectively.
Math Object
The Math object is a built-in global object that provides mathematical constants and functions for
performing various mathematical operations. It does not need to be instantiated and can be used
directly with its properties and methods.
1. Mathematical Constants:
Math.PI: Represents the mathematical constant π (pi), which is the ratio of a circle's
circumference to its diameter.
2. Trigonometric Functions:
5. Additional Functions:
Math.min(x1, x2, ..., xn) : Returns the minimum value among the provided arguments.
Math.max(x1, x2, ..., xn) : Returns the maximum value among the provided arguments.
Example
const radius = 5;
const circumference = 2 * Math.PI * radius;
console.log(`Circumference: ${circumference}`);
const randomNumber = Math.random(); // Generates a random number between 0 (inclusive) and 1 (exclusive)
console.log(`Random number: ${randomNumber}`);
In this example, we use the Math.PI property to calculate the circumference of a circle, the
Math.sin() method to find the sine of an angle, and the Math.random() method to generate a random
number.
Event Handling
Events are :
1. Event Listener:
An event listener is a function that waits for a specific event to occur. It "listens" to the event and
triggers the associated function when the event occurs. You can attach event listeners to HTML
elements to respond to events.
2. Event Object:
When an event occurs, the browser generates an event object that contains information about the
event. This object can be accessed in the event handler function to get details about the event
(e.g., mouse coordinates, key pressed, etc.).
3. Event Types:
JavaScript supports various types of events. Some common event types include:
Example
<!DOCTYPE html>
<html>
<head>
<title>Event Handling in JavaScript</title>
</head>
<body>
<button id="myButton">Click Me!</button>
<script>
// Function to handle the click event
function handleClick(event) {
JavaScript RegExp
https://youtu.be/sXQxhojSdZM
Regex (regular expressions) in JavaScript are used for pattern matching and manipulating strings.
JavaScript provides a built-in RegExp object to work with regular expressions. Regular expressions are
powerful tools that allow you to search, replace, and extract specific parts of a string based on a
pattern.
or
3. Matching:
To extract matches from a string, you can use the match() method of the string object.
4. Replacing :
You can use the replace() method of the string object to replace matches with a specified
replacement string.
5. Matching Groups :
Parentheses () can be used to create matching groups that allow you to extract specific parts of
the matched string.
Flags:
You can use flags with the regex literal to modify the behavior of the regular expression.
g (global): Matches all occurrences in the string, not just the first one.
JavaScript DOM
However, directly manipulating the DOM can be costly in terms of performance, especially when
dealing with complex web applications with frequent updates, as changes to the DOM can trigger
expensive reflows and repaints. This is where the Virtual DOM comes into play.
JavaScript validation
JavaScript validation is a technique used to validate user input on the client-side before it is submitted
to the server. This ensures that the data entered by the user meets specific criteria or follows a
particular format. Client-side validation helps to provide a more responsive and user-friendly
experience by catching errors early and reducing unnecessary server requests.
Example
<!DOCTYPE html>
<html>
<body>
<script>
function samplefun(){
var a = document.getElementById('one').value
if(a==""){
alert('This Field is mandatory!')
}
</script>
</body>
</html>
Output
In this example, we have a simple HTML form with a text input field and a button. The goal of the
JavaScript function samplefun() is to validate the input field to ensure it is not empty when the button is
clicked.
Introduction to XML
The syntax of XML
XML (eXtensible Markup Language) is a markup language that uses tags to describe data. XML is a text-
based format, which means that it can be read and understood by humans as well as machines.
The syntax of XML is very strict. The basic rules of XML syntax are:
All XML documents must have a root element. The root element is the outermost element in
the document.
<root>
<child>
<subchild>.....</subchild>
</child>
</root>
Eg:
The person element is the root element of the document. It encloses the name , age , and address
elements. The name , age , and address elements are child elements of the person element.
The root element is also used to identify the type of data in the document. In the example above, the
root element is called person , which indicates that the document contains data about a person.
All XML elements must have a start tag and an end tag. The start tag identifies the element,
and the end tag closes the element.
<p>This is a paragraph.</p>
<br />
The <p> tag is the start tag for a paragraph element in XML. The </p> tag is the end tag for a
paragraph element in XML. The paragraph element is used to contain a block of text.
XML attributes are name-value pairs that are associated with an element. Attributes are
enclosed in the start tag of the element, and they are separated by spaces.
The name attribute is associated with the person element, and the value of the name attribute is John
Doe .
XML comments are used to provide information about the XML document. Comments are
enclosed in <!-- and -->.
Document Structure
1. XML Declaration: An optional statement at the beginning of the document that specifies the XML
version being used and the character encoding. It looks like this:
2. Root Element: The top-level element that encloses all other elements in the XML document. It
serves as the entry point for parsing the document and must be unique. It should be wrapped around
all other elements. For example:
<root>
<!-- Other elements go here -->
</root>
3. Elements: Elements are the building blocks of an XML document. They are defined by a start tag,
an end tag, and the content they enclose. Elements can be nested inside other elements to create a
hierarchical structure. For example:
5. Comments: Comments are used to add explanatory notes within the XML code and are ignored by
the XML parser during processing. Comments start with <!-- and end with --> , like this:
Example
In this example, the root element is <bookstore> , which contains two <book> elements, each having
attributes (category). The <book> elements, in turn, contain child elements like <title> , <author> ,
and <year> , as well as attributes (lang) within the <title> element.
Namespaces
Namespaces in XML are used to avoid naming conflicts between elements and attributes when
combining XML documents from different sources. They provide a way to uniquely identify elements and
attributes by associating them with a namespace URI (Uniform Resource Identifier). This allows XML
documents to use the same element or attribute names within different namespaces without ambiguity.
A namespace declaration is typically done at the root element of an XML document using the xmlns
xmlns:prefix="URI"
prefix is a short identifier that is used to refer to the namespace in the document.
URI is the Uniform Resource Identifier (URI) that identifies the namespace.
Once a namespace has been declared, it can be used to refer to elements and attributes from that
namespace. For example, the above XML document uses the http://www.w3.org/1999/xhtml namespace to
refer to the html element
XML Schemas
https://youtu.be/56pR_5rO-m4
https://youtu.be/1BjmZHRHDv0
XML Schema, often referred to as XSD (XML Schema Definition), is a specification used to describe the
structure, content, and data types of XML documents. It provides a way to define rules and constraints
for the elements and attributes within an XML document, ensuring that the XML data adheres to a
specific structure.
1. Data Validation: XML Schema allows you to define the allowed structure and content of XML
documents. By validating XML against a schema, you can ensure that the data is well-formed and
conforms to the specified rules.
2. Data Modeling: XML Schema provides a way to create a model for the XML data. You can define
elements, attributes, their data types, relationships, and cardinalities, thereby establishing a blueprint
for the XML document.
XML Schema itself is written in XML format and uses elements and attributes to define the structure of
an XML document. A schema consists of several components, including:
Elements: Describes the structure and content of XML elements, including their names, data types,
occurrence constraints, and nested elements.
Data Types: Specifies the allowable data types for element content and attribute values, such as
strings, numbers, dates, etc.
Complex Types: Describes elements that contain other elements or attributes. Complex types can
have sequences, choices, and other compositor elements to define the order and occurrence of child
elements.
Simple Types: Represents atomic data types that are not composed of other elements or attributes.
Open your preferred text editor (e.g., Notepad, Notepad++, Sublime Text, Visual Studio Code,
etc.).
Copy and paste the XML content into the text editor.
You can now view and edit the raw XML content in the text editor.
There are various online XML viewers available that allow you to paste or upload the XML
content to display it in a structured format.
Alternatively, you can use browser extensions or add-ons that allow you to view XML documents
directly in your web browser with syntax highlighting.
If you prefer a code editor with advanced features, you can use editors like Visual Studio Code,
Sublime Text, or Atom. These editors often have XML syntax highlighting, making it easier to
read and navigate XML files.
You can also open an XML document in a web browser. Browsers like Google Chrome and
Firefox can display raw XML documents with syntax highlighting.
Simply save the XML content in a file with .xml extension, then open it with your web browser.
The browser will render the XML with syntax highlighting for better readability.
<?xml version="1.0"?>
<bookstore>
<book>
You can create an HTML file that includes the XML content and link to an external CSS file for styling:
<!DOCTYPE html>
<html>
<head>
<title>Styled XML Document</title>
<link rel="stylesheet" type="text/css" href="styles.css">
<pre>
<?xml version="1.0"?>
<bookstore>
<book>
<title>Book 1</title>
<author>Author 1</author>
<genre>Fiction</genre>
</book>
<book>
<title>Book 2</title>
<author>Author 2</author>
<genre>Non-Fiction</genre>
</book>
</bookstore>
</pre>
</body>
</html>
bookstore {
display: block;
font-weight: bold;
}
book {
display: block;
margin-bottom: 10px;
}
title {
color: blue;
}
author {
font-style: italic;
genre {
text-transform: uppercase;
}
The above CSS styles the <bookstore> , <book> , <title> , <author> , and <genre> elements. It's important
to note that you can only style elements that are explicitly defined in the XML structure.
<collection>
<movie>
<title> Openheimar</title>
<year>2023</year>
<genre>Biopic</genre>
</movie>
<movie>
<title> barbie</title>
<year>2023</year>
<genre>Fun</genre>
</movie>
<movie>
<title> 1983</title>
<year>2018</year>
<genre>Drama</genre>
</movie>
</collection>
file then:
movies.xsl
<xsl:template match="/collection">
<html>
<body>
<xsl:for-each select="movie">
<xsl:value-of select="title"/><br/>
<xsl:value-of select="year"/> <br/>
<xsl:value-of select="genre"/><br/>
<br/>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
The code
output
output.html
output in browser
2. Configuration Files: Many software applications use XML for storing configuration settings. XML's
hierarchical structure is ideal for representing complex configuration data.
3. Data Interchange: XML is commonly used for exchanging data between different applications or
systems. It enables seamless data sharing and interoperability.
4. RSS and Atom Feeds: XML-based formats like RSS (Really Simple Syndication) and Atom are
used for publishing and subscribing to content updates from websites, blogs, and news sources.
5. Document Formats: XML is utilized in various document formats like DocBook and DITA (Darwin
Information Typing Architecture) for creating structured and reusable content.
6. Database Integration: XML can be used to facilitate data exchange between databases and
applications, especially in heterogeneous environments.
8. Office Applications: Some office productivity tools, such as Microsoft Office (Word, Excel,
PowerPoint), utilize XML-based formats for document storage and manipulation.
9. Data Representation: XML serves as a data representation format for various applications,
including scientific data, financial data, and data exchange in supply chain management.
11. Mobile Applications: XML is used in mobile application development to store and exchange data
between the mobile app and backend services.
12. Medical Data: XML is used in healthcare and medical applications to represent patient records,
medical codes, and other clinical data.
Components of DHTML
1. HTML (Hypertext Markup Language): The foundation of web pages, defining the structure and
content of the page.
2. CSS (Cascading Style Sheets): Used to control the presentation and layout of HTML elements,
allowing for better control of the visual appearance.
3. JavaScript: The programming language used to add interactivity to web pages. JavaScript is the
primary driver of dynamic changes in DHTML, allowing developers to manipulate HTML and CSS in
real-time, respond to user actions, and create animations and effects.
4. DOM (Document Object Model): A programming interface for HTML and XML documents. It
represents the structure of a web page as a hierarchical tree of objects, which can be accessed and
manipulated using JavaScript. DOM enables dynamic modification of the content and structure of the
page.
5. Event Handling: DHTML allows developers to capture and respond to various user actions or
events, such as mouse clicks, keyboard inputs, and form submissions. JavaScript is used to handle
these events and trigger appropriate actions.
Markup language used for creating the Extension of HTML that combines JavaScript, CSS, and
Definition
structure and content of web pages. HTML for dynamic and interactive content.
Static content; no built-in support for Enables dynamic and interactive elements, allowing
Interactivity
dynamic or interactive elements. content to change, move, or update without page reload.
Limited support for handling events; Enables event handling for elements, such as click,
Events
primarily links and form submissions. hover, etc., with JavaScript.
Generally, provides a basic and Enhances user experience with interactive elements and
User Experience
straightforward user experience. real-time updates.
Simple to learn and implement for Requires proficiency in JavaScript, CSS, and HTML for
Development
static web pages. implementation.
Creating headings, paragraphs, Building sliders, dropdown menus, dynamic forms, and
Examples
images, links, etc. interactive UI components.
DHTML JavaScript
It refers to the combination of Dynamic HyperText Markup Language (DHTML) and JavaScript (Js) to
create interactive and dynamic web content. DHTML is not a separate language; rather, it's a term used
to describe the use of JavaScript, CSS, and HTML together to achieve dynamic effects and interactivity
on web pages.
JavaScript is a powerful scripting language that can be used to manipulate the Document Object Model
(DOM) of an HTML document. The DOM represents the structure of a web page, and by using
JavaScript, developers can interact with and modify the content and behavior of the page in real-time
You can include JavaScript code directly within the HTML file using the <script> element inside the
<head> or <body> section.
Inline scripting
<!DOCTYPE html>
<html>
<head>
<title>Inline Scripting Example</title>
<!-- JavaScript code inside <script> tags -->
<script>
// Your JavaScript code goes here
// For example:
function greet() {
alert('Hello, world!');
}
</script>
</head>
<body>
<h1>Inline Scripting Example</h1>
<!-- You can call the JavaScript function defined above -->
<button onclick="greet()">Click Me</button>
</body>
</html>
External Scripting
save as script.js
function greet() {
alert('Hello, world!');
}
web.html
<!DOCTYPE html>
<html>
here we link the external JavaScript file to your HTML file using the <script> element
DHTML CSS
DHTML (Dynamic HTML) and CSS (Cascading Style Sheets) are often used together to create dynamic,
interactive, and visually appealing web pages.
DHTML CSS provides:
1. Interactivity:
DHTML enables interactivity through JavaScript, allowing you to manipulate HTML elements on
the page dynamically. You can change the content, style, and behavior of elements based on
user actions (e.g., mouse clicks, hovers, form submissions).
CSS can be used to style elements that are dynamically modified by DHTML, ensuring a
consistent and visually pleasing appearance.
DHTML allows you to create animations and special effects like fading, sliding, and moving
elements on the page.
CSS can be utilized to enhance these effects, providing transitions and keyframe animations for
smoother and more visually appealing results.
3. Event Handling:
DHTML enables you to attach event handlers to HTML elements to respond to user interactions.
CSS pseudo-classes (e.g., :hover , :focus ) can be used to style elements when they are
interacted with, giving visual feedback to users.
DHTML allows you to dynamically load new content into a web page without refreshing the entire
page.
CSS styles can be applied to the newly loaded content, ensuring it fits seamlessly into the
overall design.
CSS is the primary tool for defining the layout and visual design of a web page, controlling
elements' positioning, size, colors, fonts, and more.
6. Responsiveness:
CSS is crucial for creating responsive web design, ensuring that web pages adapt to different
screen sizes and devices.
DHTML can complement this by providing interactive elements that adjust their behavior based
on the user's device or screen size.
Combining DHTML and CSS allows you to create various enhancements like image sliders,
modal dialogs, tooltips, and interactive forms.