WT 3 Unit
WT 3 Unit
Client-side scripting is when the server sends the code along with the HTML web page to the
client. The script is referred to by the code.
In other words, client-side scripting is a method for browsers to run scripts without having to
connect to a server.
The code runs on the client’s computer’s browser either while the web page is loading or after it
has finished loading.
Client-side scripting is mostly used for dynamic user interface components including pull-
down menus, navigation tools, animation buttons, and data validation.
It is currently quickly expanding and evolving on a daily basis. As a result, creating client-side
web programming has become easier and faster, lowering server demand.
By far the most popular client-side scripting languages or web scripting languages, JavaScript and
jQuery are frequently utilized to construct dynamic and responsive webpages and websites.
The browser downloads the code to the local machine (temporarily) and begins
processing it without the server. As a result, client-side scripting is browser-specific.
Client side scripts may also have some instructions for the web browser to follow
in response to certain user actions, such as pressing a page button. They can
often be looked if client want to view the source code of web page.
Popular Client Side Scripting Language
A language in which a client side script or program is written using syntax is called
client side scripting language or client side programming.
The most popular client side scripting languages is as follows:
1. JavaScript: It is the most widely client side scripting or programming
language. It is based on ECMAScript standard language.
JavaScript is an object based oriented, dynamically typed (or also called weakly
typed) scripting language. It runs directly on the browser with the help of an inbuilt
interpreter.
Here, weakly typed means the variables are easily converted implicitly from one
data type to another.
2. VBScript: This scripting language is developed by Microsoft, based on the
Visual Basic. It is basically used to enhance the features of web pages in Internet
Explorer. VBScript is interpreted by Internet Explorer web browser.
3. jQuery: jQuery is a fast, small, lightweight JavaScript library. It is used to
facilitate a lot of JavaScript code into simple-to-use-functionality.
Most of the biggest companies such as Google, Microsoft, IBM, Netflix, etc. on
the Web are using jQuery language.
Client Side Scripting Language Example
Let’s take a very simple example of JavaScript client side script. In this example, a
simple JavaScript client side script will run in the browser to display the name of
cities.
The HTML file located on the server will be the same one sent to the browser, but
JavaScript changes the HTML web page that is loaded in the browser.
Example
Look at the below diagram that shows the flow of data between server and browser.
Application of Client Side Scripting
Client side scripting is used to make web pages or website more interactive. It is
primarily used at the frontend, where the user can see using the browser.
Some important applications of client side scripting are listed, as below:
● To retrieve data from web browser or user’s screen.
● Used in the field of online games.
● To customize the web page without reloading the page.
● Client side scripting is used for validation purpose. If the user enters
incorrect credentials on the login page, the web page displays an error
message on the client machine without submitting it to the web server.
● To create ad banners that interact with the user, rather than simply
displaying graphics.
● To create animated images that change when we move the mouse over
them.
● Client side script can be used to detect installed plug-ins and notify the user
if a plugin is required.
Advantages of Client Side Scripting
There are several great advantages of client side scripting that are as follows:
1. The client side scripting language is quite easy to learn and use. It requires
minimum programming knowledge or experienced required.
2. The main advantage of client side scripting is that it is lightweight and
relatively easy to implement (syntax not too complex). The editing and
executing the code is fast.
3. Data processing is done on the client side from the server, which makes it
easier to scale applications with large numbers of users. Thereby, load on the
server reduces.
4. The client side data validation can be possible using the client side
scripting language like JavaScript.
6. Mathematical assessment is also possible using client side scripting.
7. Script code only executed by the browser without connecting the server.
Disadvantages of Client Side Scripting
There are certain disadvantages of client side scripting that are as follows:
1. The main disadvantage of client side scripting is that it is unsecure because the
code is sent as is to the client and, therefore, visible to it if the client looks at the
sources of his web page. In short, code is usually visible.
2. Client side programming cannot be used if we need to access databases or
needs to transmit sensitive data over the internet.
3. There is no guarantee that user has enabled JavaScript on his computer’s
browser. Therefore, any required functionality must be loaded on the server
despite the possibility that it could be offloaded.
4. The smooth running of the script (or program) depends entirely on the
client’s browser, its configuration, and security level.
5. The web application based on the heavy JavaScript can be complicated to
debug and maintain.
6. Client side scripting languages are usually more limited in functionality than
server side scripting language
What is JavaScript (JS)?
JavaScript (js) is a light-weight object-oriented programming language which is
used by several websites for scripting the webpages. It is an interpreted, full-
fledged programming language that enables dynamic interactivity on websites
when applied to an HTML document. It was introduced in the year 1995 for adding
programs to the webpages in the Netscape Navigator browser. Since then, it has
been adopted by all other graphical web browsers. With JavaScript, users can
build modern web applications to interact directly without reloading the page
every time. The traditional website uses js to provide several forms of interactivity
and simplicity.
JS is the most popular programming in the world right now. It is growing faster
than any other language. Big companies like PayPal, Netflix and more build
internal applications around JS.
showing animations.
install any software. There is also a browser console where you can
responses, to browser
Introduction to JavaScript
JavaScript is a scripting language that is used to create and manage dynamic web
pages, basically anything that moves on your screen without requiring you to
refresh your browser. It can be anything from animated graphics to an
automatically generated Facebook timeline.
When most people get interested in web development, they start with good old
HTML and CSS. From there, they move on to JavaScript, which makes sense,
because, these three elements together form the backbone of web development.
● HTML is the structure of your page like the headers, the body
text, any images you want to include. It basically defines the
contents of a web page.
● CSS controls how that page looks (it’s what you’ll use to
customize fonts, background colors, etc.).
JavaScript is used in various fields from the web to servers, and here’s a quick list
of the significant areas it’s used in:
The next step is to write code. Here’s how you can write a simple JavaScript code
that prints Hello World on the browser window.
<html>
<body>
<script language="javascript" type="text/javascript">
document.write("Hello World!");
</script>
</body>
</html>
● JavaScript can be easily integrated into the HTML code, and that’s
exactly what’s happening here.
● For those of you not familiar with HTML, this code might seem a bit
unfamiliar. But it is perfectly understandable even to web development
beginners.
● <html> tag is required to define a HTML web page. <head> tag. The web
page contents are defined inside the <body> tag.
● Any JavaScript that you add to the web page has to be within the <script> tag.
● document.write is a JavaScript function that writes the contents onto the
web page. In this case, it prints “Hello World!” on screen.
While HTML and CSS are absolutely required to code a basic web page, JavaScript
is the language that will help you bring that page to life, making it more attractive
to the audience. Taking the time to learn JavaScript will help you in the web
development world.
JavaScript Code
<html>
<head></head>
<body>
<h1>Check the console for the message!</h1>
<script>
// This is our first JavaScript program
console.log("Hello, World!");
</script>
</body>
</html>
In this example
Features of JavaScript:
There are many features of JavaScript which are as follows:
Light eight
Dynamic typing
Object-oriented programming
Functional Style
Prototype-based
Interpreted Language
It supports single threading which means it can only do a single task at a time but
JavaScript can implement parallel execution with the help of async processing and
web workers.
Async Processing: If there are many functions that need to be executed then
utilizing async processing allows us to process functions in parallel that means
functions are not executed one by one but can be executed in parallel.
Web Worker: When there is heavy-duty work then web worker is utilized to run
tasks in background threads by processing a parallel execution.
Zero-based numbering
Applications of JavaScript
There are multiple applications of JavaScript, some of them are as follows:
Web Development:
Server applications:
Web Applications:
Web applications are constructed with the help of JavaScript. The frameworks of
JavaScript such as Angular, React, etc., are utilized to build robust web apps.
Game development:
JavaScript is a great language for creating games on the web. Both HTML5 and
JavaScript are used together to develop games. The library called EaselJS provides
rich graphics so it is utilized for graphics. Some of the games created using HTML5
and JS are Rock Paper Scissor, Snake Game, Tic Tac Toe, etc.
Presentations:
Mobile applications are very popular these days as they are convenient to use.
There are various frameworks of JavaScript such as React Native, Apache
Cordova, Mobile Angular UI, jQuery Mobile, and more, are used to create mobile
applications. Some of the mobile apps created using JS frameworks are Netflix,
Candy Crush, Uber, Facebook, etc.
HTML in JavaScript provides a feature called the canvas element which is used to
make drawings on web pages. This feature has opened a gateway for creating
digital art projects. The canvas element allows us to draw freely, provides many
colors, and much more.
Smartwatches are getting popular these days as they act as a substitute for
mobiles. JS libraries like Pebble are utilized for creating apps for smartwatches.
JavaScript consists of a library called Chart.js which is utilized to create charts and
reports. The Chart.js provides various features such as device pixel ratio, data
decimation, responsive charts, etc.
keystrokes) in real-time.
● Asynchronous: JavaScript can handle tasks like fetching data from
user events like clicks and form inputs. Libraries such as AngularJS,
handle actions.
how it’s done. It emphasizes describing the desired result, like with
development.
like Ease JS, enables the creation of interactive games for the web.
Limitations of JavaScript
● Security Risks : JavaScript can be used for attacks like Cross-Site
<script> tags.
meaning variables don’t require explicit types. This can lead to issues
● DataTypes
●
∙ Numbers - are values that can be processed and calculated. You don't
enclose them in quotation marks. The numbers can be either positive
or negative.
● ∙ Strings - are a series of letters and numbers enclosed in quotation
marks. JavaScript uses the string literally; it doesn't process it. You'll
use strings for text you want displayed or values you want passed
along.
● ∙ Boolean (true/false) - lets you evaluate whether a condition
meets or does not meet specified criteria.
● ∙ Null - is an empty value. null is not the same as 0 -- 0 is a real,
calculable number, whereas null is the absence of any value.
● Data Types
TYPE EXAMPLE
Numbe Any number, such as 17, 21, or 54e7
rs
Strings "Greetings!" or "Fun"
Boole Either true or false
an
Null A special keyword for exactly that – the null value
(that is, nothing)
JavaScript variables are used as container to store values, and they can be of any
data type. You can declare variables using the var, let, or const keywords.
JavaScript provides different ways to declare multiple variables either individually
or in a single line for efficiency and readability.
I variable is a name given to the memory location that helps us to store some
form of data and retrieves it when required. It allows us to refer to memory
location without having to memorize the memory address. A variable name can
be used in expressions as a substitute in place of the value it stores.
console.log(a);
console.log(b);
console.log(c);
JavaScript Variables
The following are the rules for naming variables in JavaScript:
variable names.
not be taken.
name variables.
The var keyword was used in all JavaScript code from 1995 to 2015.
The var keyword should only be used in code written for older browsers.
The let and const keywords were introduced to JavaScript in 2015 (ES6). Prior to
ES6, only var keyword was used to declare the variable in JavaScript. In this
section, we will discuss 'var' keyword. We will cover the 'let' and 'const' keywords
in subsequent chapters.
You
The let keyword in JavaScript is used to declare a block-scoped local variable, optionally
initializing it to a value. It’s part of the ECMAScript 2015 (ES6) specification. Variables declared
with let have their scope in the block for which they are defined, as well as in any contained sub-
blocks. This differs from
variables declared with var, which have their scope in the entire enclosing function.
The let keyword in JavaScript is used for declaring a variable with block scope,
potentially initializing it to a value. The syntax is as follows:
1. Declaration
let variableName;
2. Initialization
Where,
1. Declaration
var variableName;
2. Initialization
Where,
Characteristics of ‘var‘
● Function Scope: Variables declared with var are scoped to the
nearest function block. If declared outside of a function, they are
globally scoped.
● Hoisting: var declarations are “hoisted” to the top of their scope. This
means that the variable can be used before it’s declared, although it will
be undefined until its declaration and initialization (if any) are reached in
● Re-Declaration: Variables declared with var can be re-declared
within the same scope without causing an error, which can lead to
bugs if done accidentally.
● Initialization: If you declare a variable with var without initializing it (i.e.,
without assigning it a value), it will have the value undefined.
1. Basic Usage
The var keyword in JavaScript is used to declare a variable. It’s one of the ways to
store data values, and its usage has several characteristics that distinguish it from
other variable declaration keywords like let and const.
3. Declaration
var variableName;
4. Initialization
Where,
Characteristics of ‘var‘
2. Basic Usage
Example: This example shows the declaration of some constant by using the
const keyword.
For example:
If we add 3 and 7, we
get 10 as a result.
3+7=10
In this case, 3 and 7 are operands, whereas + is an operator.
JavaScript Arithmetic
add values.
together.
y=
z=
2;
x=y+z;
variables. Given that x=10 and y=5, the table below explains the
assignment operators:
the + operator.
txt1="What a very";
txt2="nice day";
txt3=txt1+txt2;
After the execution of the statements above, the variable txt3 contains
"What a verynice day". To add a space between the two strings, insert a
x="5"+"5";
document.write(x);
x=5+"5";
document.write(x);
x="5"+5;
document.write(x);
The rule is:
Comparison and Logical operators are used to test for true or false.
Comparison Operators
Given that x=5, the table below explains the comparison operators:
Operator Description Example
== is equal to x==8 is false
=== is exactly equal to (value and type) x===5 is true
x==="5" is false
!= is not equal x!=8 is true
> is greater than x>8 is false
< is less than x<8 is true
>= is greater than or equal to x>=8 is false
<= is less than or equal to x<=8 is true
You will learn more about the use of conditional statements in the
next chapter of this tutorial. Logical Operators
variables or values. Given that x=6 and y=3, the table below
Operator Description Example
explains
&& the logical operators: and (x < 10 && y > 1) is true
Conditional Operator
Example
greeting=(visitor=="PRES")?"Dear President ":"Dear ";
If the variable visitor has the value of "PRES", then the variable
greeting will be assigned the value "Dear President " else it will be
assigned "Dear".
If the variable visitor has the value of "PRES", then the variable
greeting will be assigned the value "Dear President " else it will be
assigned "Dear"
What are JavaScript Operators?
In JavaScript, we have various types of operators.
● Arithmetic Operators
● Assignment Operators
● Logical Operators
● Bitwise Operators
Arithmetic Operators
+ Add 7+3=10
– Subtract 7-3=10
* Multiply 7*3=21
/ Divide 7/3=2.34
If one of the operands is a string, the result of the operation is a string, according to these rules:
num1 + num2
Example:
If both operands are strings, the second string is concatenated to the first.
If only one operand is a string, the other operand is converted to a string, and the
result is the concatenation of the two strings.
If single or both operands are decimal values, then it returns the decimal values.
Infinity added to –Infinity results NaN.
This behavior of add operator is a source of common mistakes, as this code snippet shows:
Syntax: You just need to write two integers. These two integers are stored in variables num1 and
num2, respectively. Then, these two numbers are added using the + operator, and the result is
printed in the console.
Syntax: You just need to write two integers. These two integers are stored in variables num1 and
num2 respectively. Then, these two numbers are subtracted using the - operator, and the result
is printed in the console.
num1 - num2
Examples:
Multiplication Operator:
This JavaScript arithmetic operator multiplies the two operands together. Multiplication
Operator is defined as (*) and multiply two value and return a product.
Infinity multiplied by 0 results NaN.
Infinity multiplied by Infinity results Infinity.
If Infinity is multiplied by any finite number other than 0, the result is either Infinity
or –Infinity, depending on the sign of the second operand.
Syntax: You just need to write two integers. These two integers are stored in variables num1 and
num2, respectively. Then, these two numbers are multiply using the * operator, and the result is
num1 * num2
Examples:
Syntax: You just need to write two integers. These two integers are stored in variables num1 and
num2, respectively. Then, these two numbers are divided using the / operator, and the result is
printed in the console.
num1 / num2
Examples:
This JavaScript arithmetic operator gives the remainder of the left operand when divided by the
right operand. It is also known as the Remainder operator. Modulus Operator is defined as (%)
and divides two value and return a remainder. Using the Modulus operator, we can find the
number is odd or even if we do a number modulo 2 answer is zero then it means the number is
even. If we do a number modulo 2 answer is one, then it means the number is odd.
Syntax: You just need to write two integers. These two integers are stored in variables num1 and
num2, respectively. Then, these two numbers use the % operator to calculate the modulus of the
If the dividend is an infinite number and the divisor is a finite number, modulus
results NaN.
If the dividend is zero and the divisor is nonzero, modulus results zero.
num1 % num2
Examples:
var num1 = 1;
var num2 = 2;
console.log("1 % 2 = " + (num1 % num2)); // 1 % 2 = 1
Syntax: You just need to write two integers. These two integers are stored in variable num1 and
num2, respectively. Then, these two numbers are Exponentiation using the ** operator, and the
result is printed in the console.
num1 ** num2
Examples:
var num1 = 2;
var num2 = 2;
console.log("2 ** 2 = " + (num1 ** num2)); // 2 ** 2 = 4
Increment Operator:
This JavaScript arithmetic operator increases the value of the operand by one. Increment
Operator is defined by a double plus sign (++). This is a unary operator, x++ produces a value of
x before adding 1 to x. This is called the post-increment operator, since the value is produced,
and then the variable is incremented. On the other hand,++x produces a value of x after adding 1
to x. This is called the pre-increment operator,
Syntax: You just need to write integers. This integer is stored in variable x respectively. Then, this
numbers is incremented using the ++ operator, and the result is printed in the console.
Examples:
var x = 20;
var y = ++x; // y is 21, x is 21
console.log(x)
console.log(y)
Decrement Operator:
This JavaScript arithmetic operator decreases the value of the operand by one. Decrement
Operator is defined by a double minus sign (--). This is a unary operator, x-- produces
a value of x
before subtracting 1 to x. This is called the post-decrement operator, since the value
is
produced, and then the variable is decremented. On the other hand, --x decrements
the variable
first, and then produces the value the pre-decrement operator.
Syntax: You just need to write integers. This integer is stored in variable x
respectively. Then, this
numbers is decremented using the -- operator, and the result is printed in
the console.
x-- //Post-decrement Operator
--x //Pre-decrement Operator
Examples:
var x = 20;
x--; // x returns 19
console.log(x)
var x = 20;
var y = x--; // y is 20, x is 19
console.log(x)
console.log(y)
var x = 20;
var y = --x; // y is 19, x is 19
console.log(x)
console.log(y)
Assignment Operators
The assignment operator assigns the value, variable, and function to another
Operator Description
= Assign
== Equal to 3 == 5 // false
For example,
For example,
true if both the values and the types of the operands are the same.
false if either the values or the types of the operands are not the same.
For example,
true if either the values or the types of the operands are not the same.
false if both the values and the types of the operands are the same.
For example,
true if the value on the left is greater than the value on the right.
false if the value on the left isn't greater than the value on the right.
For example,
console.log(2
For example, > 5); // false
true if the value on the left is greater than or equal to the value on the
right.
false if the value on the left is less than the value on the right.
7. Less Than Operator
true if the value on the left is less than the value on the right.
false if the value on the left isn't less than the value on the right.
For example,
Run Code
For example,
Run Code
// Output: true
// left operand is greater
Run Code
const x = 5, y = 3; console.log((x <
Here, && is the logical operator AND. Since both the boolean expressions x <
6) && (y < 5))
6 and y < 5 are true, evaluating them with the && operator also results in true.
let x = 2;
Run Code
Here,
● (x < 4) && (4 >= x) results in true because both expressions are true.
● (x <= 4) && (2 == 4) results in false because the expression 2 == 4
2. Logical OR Operator
The logical OR operator || returns true if at least one expression is true. For
example,
2. Logical OR Operator
The logical OR operator || returns true if at least one expression is true. For
example,
let x = 2;
Run Code
Here,
// NOT on true
console.log(!true); // false
// NOT on false
console.log(!false); // true
// comparison example
Here,
1. Using if Statement
if (x % 2 === 0) {
console.log("Even");
if (x % 2 !== 0) {
console.log("Odd");
};
The if-else statement will perform some action for a specific condition. Here we
are using the else statement in which the else statement is written after the if
statement and it has no condition in their code block.
1. else if Statement
As the number of conditions increases, you can use multiple else-if statements in
JavaScript. but when we dealing with many conditions, the switch statement may
be a more preferred option.
const marks = 85;
let Branch;
switch (true) {
case marks >= 90:
Branch = "Computer science engineering";
break;
case marks >= 80:
Branch = "Mechanical engineering";
break;
case marks >= 70:
Branch = "Chemical engineering";
break;
case marks >= 60:
Branch = "Electronics and communication";
break;
case marks >= 50:
Branch = "Civil engineering";
break;
default:
Branch = "Bio technology";
break;
}
} else {
console.log("Check the weather forecast!");
};
TpointT
ech
TpointT
ech
TpointT
ech
Explanation
In this example
In the while loop, we specify the condition before the loop, and usually, some
variable is incremented or changed in the while loop body to determine when
the loop should stop.
Syntax
The syntax of while loops is as follows:
while(condition){
//code block to be executed
}
Example
let a = 0;
while(a <= 3){
console.log("Welcome to
TpoinTech"); a++;
}
Output:
Welcome to
TpoinTech
Welcome to
TpoinTech
Welcome to
TpoinTech
Welcome to
TpoinTech
Explanation
In this example, the while loop will run as long as the condition a <= 3 is true.
Since a starts at 0 and increments by 1 in each iteration, the loop will run 4
times (0, 1, 2, 3). After the 4th iteration, a will be 4, and the condition a <= 3 will
be false, so the loop will exit.
In JavaScript, do-while loops are used when the loop body needs to be executed
at least once. The loops end when the condition is false.
Syntax
do{
//code to execute
}while(condition)
Example
let p =
1; let q
= 1; do{
pp = p + q;
console.log(p);
q++;
}while(q<5)
Output:
2
4
7
11
Explanation
○ An array of elements.
○ A string of characters.
○ A map of key/value pairs.
Syntax
for(variable of iterable){
//code to execute
}
Example
const items = ['BMW', 'Ferrari',
'Mustang']; for(const item of items){
console.log(item);
}
Execute Now
Output:
BMW
Ferrari
Mustang
Syntax
Example
const items = {Phone: 2, Laptop: 1, TV:
1}; for(const Appliance in items){
console.log(Appliance);
}
Output:
Pho
ne
Lapt
op
TV
And if you want to access the values:
Output:
2
1
1
JavaScript provides various popup boxes to notify, warn, or to get input from the
user. Popup boxes prevent the user from accessing other aspects of a program
until the popup is closed, so they should not be overused.
● Alert box
● Confirm box
● Prompt box
JavaScript Alert Box
An alert dialog box is mostly used to inform or alert the user by displaying some
messages in a small dialogue box. Following is the syntax for it:
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Alert</h2>
<script>
function myFunction() {
alert("I am an alert
box!");
}
</script>
</body>
</html>
JavaScript Confirm Box
A confirmation box is used to let the user make a choice. When Javascript pops up
a confirm box, the user will have to click either "OK" or "Cancel" to proceed to the
next step.
Also, based on what the user clicks on we can perform different actions. We can
specify this course of action with conditional logic.
When the user clicks on the OK button then the result variable will get the value
true and if the user clicks on the Cancel button the result variable will get the
value false.
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
function
myFunction() { var
txt;
if (confirm("Press a
button!")) { txt = "You
pressed OK!";
} else {
txt = "You pressed Cancel!";
}
document.getElementById("demo").innerHTML = txt;
}
</script>
</body>
</html>
Javascript Prompt Box can be used when we want to get some user input. When
Javascript displays a prompt box, the user will see a popup box with an input field
and buttons "OK" or "Cancel" to proceed after entering an input value.
Here, SOME MESSAGE is the message which is displayed in the popup box, and
DEFAULT_VALUE is the default value in the input field. The default value is an
optional field.
The value returned by the prompt depends on what exactly the user does with the
dialog.
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Confirm Box</h2>
<p id="demo"></p>
<script>
function
myFunction() { var
txt;
if (confirm("Press a
button!")) { txt = "You
pressed OK!";
} else {
txt = "You pressed Cancel!";
}
document.getElementById("demo").innerHTML = txt;
}
</script>
</body>
</html>
Now that we know about the three popup boxes that we can create and use in
JavaScript, let's cover a few usecase where we can use them.
JavaScript Alert box can be used to show any error message or any help message.
For example, if you perform form field validation, and you find some field value
incorrect, you can show an alert box with a message to inform user about the
incorrect input.
JavaScript Confirm box is a good way to confirm any important user action like if
we have a feature in our web application where upon clicking a button, we make
an AJAX call to the server to delete some data from the database, in such cases,
it's better to confirm once when the button is clicked to give the user a second
chance to confirm or cancel the request if its done by mistake. So, for important
actions, we should use the confirm popup box.
JavaScript Events
The change in the state of an object is known as an Event. In html, there are
various events which represent that some activity is performed by the user or by
the browser. When javascript code is included in HTML, js react over these events
and allow the execution. This process of reacting over the events is called Event
Handling. Thus, js handles the HTML events via Event Handlers.
For example, when a user clicks over the browser, add js code, which will execute
the task to be performed on the event.
Mouse events:
Keyboard events:
Keydown & Keyup onkeydown & onkeyup When the user press and
then release the key
Form events:
Window/Document events
Click Event
<html>
<head> Javascript Events </head>
<body>
<script language="Javascript" type="text/Javascript">
<!--
function clickevent()
{
document.write("This is Tpoint Tech");
}
//-->
</script>
<form>
<input type="button" onclick="clickevent()" value="Who's this?"/>
</form>
</body>
</html>
Explanation:
MouseOver Event
<head>
<h1> Javascript Events </h1>
</head>
<body>
<script language="Javascript" type="text/Javascript">
<!--
function mouseoverevent()
{
alert("This is Tpoint Tech");
}
//-->
</script>
<p onmouseover="mouseoverevent()"> Keep cursor over me</p>
</body>
</html>
Explanation:
Focus Event
<html>
<head> Javascript Events</head>
<body>
<h2> Enter something here</h2>
<input type="text" id="input1" onfocus="focusevent()"/>
<script>
<!--
function focusevent()
{
document.getElementById("input1").style.background=" aqua";
}
</script>
</body>
</html>
Explanation:
Explanation:
<!DOCTYPE html>
<html>
<body>
<h3>Type a character</h3>
<div id="output"></div>
<script>
});
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<div id="output"></div>
<script>
document.getElementById('output').innerHTML =
});
</script>
</body>
</html>
Form Events
The form events in JavaScript are events that are associated with HTML forms.
These events are triggered by user actions when interacting with form elements
like text fields, buttons, checkboxes, etc. Form events allow you to execute
JavaScript code in response to these actions, enabling you to validate form data,
perform actions on form submission or reset, and enhance the user experience.
JavaScript form events are hooked onto the elements in the Document Object
Model also known as DOM where by default the bubbling propagation is used i.e.
from bottom (children) to top(parent).
Form Description
Event
onsub Triggered when a form is submitted. It's often used for form validation
m it before data is sent to the server.
onrese Triggered when the form is reset, allowing you to perform actions
t when the user resets the form.
onchan Triggered when the value of a form element (input, select, textarea)
ge changes. Commonly used for user input validation or dynamic updates.
</body>
</html>
The following example highlights the onsubmit event's functionality upon form
submission. The form features a username field and password field; both must be
filled for successful validation when invoking the validateForm function. Upon
passing this validation, submitting the form will trigger display of a confirmation
message.
<!DOCTYPE html>
<html>
<body>
<label for="username">Username:</label>
<label for="password">Password:</label>
<br/>
</form>
<script>
function validateForm() {
var username =
document.getElementById('username').value;
var password =
document.getElementById('password').value;
// Perform validation
fields");
</script>
</body>
</html>
In this demonstration, we observe the onreset event in action: it triggers upon the
user's click of the "Reset" button within a form. The resetForm function once
invoked, clears the form content filled by user and then displays an alert to
confirm successful reset of said form.
<!DOCTYPE html>
<html>
<body>
<form onreset="resetForm()">
<label for="email">Email:</label>
</form>
<script>
function resetForm() {
</script>
</body>
</html>
The onfocus and onblur events merge in this example. The user's focus on the
input field triggers a call to the handleFocus function, which then logs a message
into the console. In contrast, when clicks outside of or tabs away from said input
field this action triggers execution of another function called handleBlur that
subsequently records an alternative message within that same console log.
<!DOCTYPE html>
<html>
<body>
<label for="name">Name:</label>
<script>
handleFocus() {
function handleBlur() {
</script>
</body>
</html>
Window Events
At the browser level, window events happen and hold association with the
window object; this global object represents the web browser's window.
Frequently employed to oversee the overall state of a browser window or
manage global interactions are these types of events.
loaded successfully" and "document.write" function will help to write the returned
string on the document.
Event Description
Name
load Triggered when the entire web page, including all its resources, has
finished loading.
unload Fired when the user is leaving the page or closing the browser
window or tab.
resize Activated when the size of the browser window is changed.
Load event
<html>
<head>Javascript Events</head>
</br>
<body onload="window.alert('Page successfully loaded');">
<script>
<!--
document.write("The page is loaded successfully");
//-->
</script>
</body>
</html>
Explanation:
In the above example, we created an "onload" event on the html's <body> tag. When a HTML
body will be loaded then a function will return a string "The page is
JavaScript Arrays
○ Array Literals
○ Using new keyword
○ Array Constructor
Array Literal
An array literal is a list of zero or more expressions, each of which represents an
array element, enclosed in square brackets([]).
Syntax
The array can be created with an array literal by using the syntax below.
i<country.length; i++ ){
console.log( country[i]);
}
Output:
India
Australia
England
Syntax
Japan
Spain
Germa
ny
Array Constructor
You can create an array instance by passing arguments into a constructor.
Example
let employee = new Array("Rohit", "Vivek",
"Jhon"); for (let i=0;i<employee.length;i++){
console.log(employee[i]);
}
Output:
Rohit
Vivek
Jhon
Example
let cars = ["BMW", "Buggati", "Skyline"];
console.log(cars[1]);
Output:
Buggati
Example
let cars = ["BMW", "Buggati", "Skyline"];
console.log(cars[0]);
Output:
BMW
Example
let cars = ["BMW", "Buggati",
"Skyline"]; let last = cars[cars.length-
1]; console.log(last);
Output:
Skyline
Example
let cars = ["BMW", "Buggati", "Skyline"];
cars[1] = "Ferrari";
console.log(cars);
Output:
Example
let cars = ["BMW", "Buggati", "Skyline"];
cars.push("GTR");
console.log(cars);
Output:
Example
let cars = ["BMW", "Buggati", "Skyline"];
cars.pop(); // removes the last element
console.log(cars);
Output:
[ 'BMW', 'Buggati' ]
Syntax
The unshift() method is represented by the following syntax:
Parameter
element1,element2, ... ,elementn - The elements to be added.
Return
The original array with added elements.
Example 1
Here, we will add an element in the given array.
<script>
var
arr=["AngularJS","Node.js"];
var result=arr.unshift("JQuery");
document.writeln(arr);
</script>
Output:
JQuery,AngularJS,Node.js
JavaScript Array Methods
Let's see the list of JavaScript array methods with their description.
Methods Description
Objects in Javascript
An object in JavaScript is a data structure used to store related data collections.
It stores data as key-value pairs, where each key is a unique identifier for the
associated value. Objects are dynamic, which means the properties can be
added, modified, or deleted at runtime.
There are two primary ways to create an object in JavaScript: Object Literal
and Object Constructor.
The object literal syntax allows you to define and initialize an object with curly
braces {}, setting properties as key-value pairs.
let obj = {
name: "Sourav",
age: 23,
job: "Developer"
};
console.log(obj);
Output
{ name: 'Sourav', age: 23, job: 'Developer' }
console.log(obj);
Output
{ name: 'Sourav', age: 23, job: 'Developer' }
You can access an object’s properties using either dot notation or bracket
notation
console.log(obj.name);
Output
Sourav
23
Output
{ name: 'Sourav', age: 22 }
{ name: 'Sourav', age: 23 }
You can dynamically add new properties to an object using dot or bracket
notation.
console.log(obj);
Output
{ model: 'Tesla', color: 'Red' }
console.log(obj);
Output
{ model: 'Tesla' }
Output
false true
Output name:
Sourav age: 23
7. Merging Objects
Output
{ name: 'Sourav', age: 23 }
8. Object Length
Output
2
Output
true
// Object literal
const obj1 = { key: "value" };
console.log(obj1); console.log(obj2);
Output
{ key: 'value' }
{ key: 'value' }
At first glance, both approaches seem to achieve the same result. However,
there are significant differences to understand.
Literal syntax is
Useful only in
Customization sufficient for most use
rare
cases.
scenarios.
Why Is {} Preferred?
Functions in JavaScript
Functions in JavaScript are reusable blocks of code designed to perform specific
tasks. They allow you to organize, reuse, and modularize code. It can take inputs,
perform actions, and return outputs.In JavaScript, a function is a reusable block
of code that can be defined and then executed whenever needed.
Functions are one of the fundamental building blocks of JavaScript and play a
function sum(x, y) {
return x + y;
}
console.log(sum(6, 9));
9. Checking if a Property Exists
Output
false true
Output name:
Sourav age: 23
Output
{ name: 'Sourav', age: 23 }
Output
2
Output
true
// Object literal
const obj1 = { key: "value" };
console.log(obj1); console.log(obj2);
Output
{ key: 'value' }
{ key: 'value' }
At first glance, both approaches seem to achieve the same result. However,
there are significant differences to understand.
Literal syntax is
Useful only in
Customization sufficient for most use
rare
cases.
scenarios.
Why Is {} Preferred?
Functions in JavaScript
Functions in JavaScript are reusable blocks of code designed to perform specific
tasks. They allow you to organize, reuse, and modularize code. It can take inputs,
perform actions, and return outputs.In JavaScript, a function is a reusable block
of code that can be defined and then executed whenever needed.
Functions are one of the fundamental building blocks of JavaScript and play a
function sum(x, y) {
return x + y;
}
console.log(sum(6, 9));
After defining a function, the next step is to call them to make use of the
function. We can call a function by using the function name separated by the
value of parameters enclosed between the parenthesis.
// Function Definition
function welcomeMsg(name) {
return ("Hello " + name + " welcome to LNCT");
}
let nameVal = "User";
// calling the function
console.log(welcomeMsg(nameVal));
Why Functions?
● Functions can be used multiple times, reducing redundancy.
keyword.
parameters.
pieces.
Introduced in ES6, arrow functions allow for a more concise and readable code,
don’t have their own this, but instead, inherit it from the surrounding context.
● Arrow functions are written with the => symbol, which makes them
compact.
● They don’t have their own this. They inherit this from the
surrounding context.
console.log(add(5, 3));
Output 8
JavaScript Callbacks
In JavaScript, callbacks play an essential role in handling asynchronous tasks like
reading files, making API requests, and executing code after certain events. If
you’ve ever heard the phrase “I will call back later!”, that’s exactly how
callbacks work.
function sayBye() {
console.log("Goodbye!");
}
greet("Ajay", sayBye);
Output Hello,
Ajay Goodbye!
An anonymous function is simply a function that does not have a name. Unlike
named functions, which are declared with a name for easy reference,
anonymous functions are usually created for specific tasks and are often assigned
greet("LNCT!");
Arrow functions
the same, except here we don’t need the function keyword also. Here, we define
the function by a single parenthesis and then ‘=>’ followed by the function body.
Pure functions return the same output for the same inputs and do not produce
side effects. They do not modify state outside their scope, such as modifying global
operations.
function pureAdd(a, b) {
return a + b;
}
console.log(pureAdd(2, 3));
Output
You can thank JavaScript for the way you navigate the web by using a drop-down
arrow to scroll to the bottom of a page, the
auto-suggestions in search, and any live content updates.
Before JavaScript, everything had to be static, but now we can see some of the
most complex content that responds to a variety of interactions. Zooming, videos,
audio, and anything else that requires a change without the whole page
refreshing is thanks to JavaScript.
2. Server-Side Development
Initially, JavaScript was only used in web browsers, but with Node.js, it is now
possible – and very much expected – to write and execute JavaScript on the
server side.
This is yet another example of what JavaScript is used for. Using JavaScript’s
runtime environment, Node.js, developers can create scalable and high-
performance web servers, manage databases, and handle authentication
processes. All of this makes it a viable option in 2025.
Facebook is one popular company that uses JavaScript to power its online
community. React, and the corresponding React Native are two JavaScript
frameworks built by Facebook. By using both of these, you can use a single code-
base across iOS and Android apps instead of writing entirely separate code for
each.
This is one of many reasons why companies like Netflix and Uber also like to
leverage JavaScript for their front-end interactions. The result is that these
companies have apps that are responsive and dynamic, perfect for their needs.
4. Game Development
JavaScript can be utilized to develop games for web browsers. GitHub features a
collection of game engines, many of them employing HTML5 as well.
JavaScript is even being used in the virtual reality industry with the help of the
WebXR Device API, allowing developers to create immersive gaming experiences.
Many modern browser-based games on the market at the moment rely on
JavaScript for real-time rendering and physics-based interactions.
5. Desktop Application Development
We have already discussed how JavaScript can be used in both mobile and web
development. But with the rise of tools and frameworks like Electron.js,
developers can now build desktop applications using JavaScript, HTML, and CSS,
providing
cross-platform compatibility.
This means that a lot of browser-based apps can maintain consistency when their
respective app is installed on a phone or computer.
Well-known applications such as Slack, Visual Studio Code, and Discord are built
using Electron, leveraging JavaScript’s efficiency and flexibility to deliver seamless
user experiences across operating systems.
6. AI & Machine Learning Applications
JavaScript has libraries that support development for AI-related projects as well.
Tensorflow.js, for instance, is a JavaScript library for machine learning. You can
build and train machine learning models using the library.
Popular uses for AI applications that have been built with JavaScript can vary, but
some popular examples we have come across here at Trio include apps or
components of apps that take care of image recognition, chatbot development,
and predictive analytics.
JavaScript also lets developers integrate machine learning into their web and
mobile apps. This has various uses in dealing with big data.
jQuery
The main purpose of jQuery is to provide an easy way to use JavaScript on your
website to make it more interactive and attractive. It is also used to add
animation.
What is jQuery
jQuery is a small, light-weight and fast JavaScript library. It is cross-platform and
supports different types of browsers. It is also referred as ?write less do more?
because it takes a lot of common tasks that requires many lines of JavaScript code
to accomplish, and binds them into methods that can be called with a single line
of code whenever needed. It is also very useful to simplify a lot of the complicated
things from JavaScript, like AJAX calls and DOM manipulation.
○ Microsoft
○ Google
○ IBM
○ Netflix
Features-
Jquery installing
r simple step-by-step guide on how to install and use jQuery, depending on your
setup:
<p>Click me!</p>
<script>
$(document).ready(function(){
$('p').click(function(){
alert("You clicked the paragraph!");
});
});
</script>
</body>
</html>
$(document).ready(function() {
console.log("Hello from jQuery!");
});
jQuery Syntax
The jQuery syntax is tailor-made for selecting HTML elements and performing
some action on the element(s).
Examples:
$(document).ready(function(){
$(selector).action()
});
Any jQuery statement starts with a dollar sign $ and then we put a selector inside
the braces (). This syntax $(selector) is enough to return the selected HTML
elements, but if you have to perform any action on the selected element(s) then
action() part is required.
The factory function $() is a synonym of jQuery() function. So in case you are using
any other JavaScript library where $ sign is conflicting with some
thing else then you can replace $ sign by jQuery name and you can use function
jQuery() instead of $().
Examples
Below are few examples to illustrate the basic jQuery Syntax. Following example
will select all the <p> elements from an HTML document and will hide those
elements. jQuery code:
<!doctype html>
<html>
<head>
<title>The jQuery Example</title>
<script
src="https://www.tutorialspoint.com/jquery/jquery-3.6.0.js"></sc ript>
<script>
$(document).ready(function() {
$("p").hide()
});
</script>
</head>
<body>
<h1>jQuery Basic Syntax</h1>
<p>This is p tag</p>
<p>This is another p tag</p>
<span>This is span tag</span>
<div>This is div tag</div>
</body>
</html>
Some essential functions of jQuery for web designing
As a beginner web developer, you must know its basic functions in web
development. It will make it easier to use JavaScript in web page development.
Also, if you plan to enrol on graphics and animation courses, you can learn about
jQuery functions from there. Here, we will list some most popular jQuery
functions that are widely used in web page designing-
Hide function
The hide function of jQuery helps you hide any selected HTML element with
simple steps. All you need to do is to call the function and follow the process. As
a result, when you script the hide function for a selected element, it hides the
element from your page. You can learn more about jQuery functions and web
design from Moople Web Design Institute.
Show function
This jQuery function works opposite to the hide function. It lets you display or
show the hidden HTML element using the hide function. So, you must learn the
hide function first to learn the show function. What you will show is simple if all
your HTML elements are already displayed on the web page.
Therefore, before you apply the show function on any HTML element of the web
page, you must use the hide function on the same HTML element.
slideUp function
The slide Up function of jQuery also lets the developers hide any selected
HTML element without using the hide function. The slide Up function is a cool
alternative to the hide function to help you hide any selected HTML element.
The function helps to slide the selected HTML element up and remove it
slowly.
The most interesting feature of this jQuery function is that it helps you
control the sliding speed, making it most accessible and effective.
slideDown function
Like the slide Up (an alternative to hide), the slide Down function is an alternative
to the show function. The slide Down function helps show the selected HTML
element. The slide Down function allows you to show your selected HTML
element on the web page, similar to the show function. But it works more
effectively as you can control how the HTML element appears on your webpage.
The graphics and animation courses can help you learn about jQuery and other
programming languages. Also, Moople can offer quality web designing and
animation courses in Kolkata.
Toggle function
The toggle function is another essential function of jQuery for web designing. The
toggle function is a versatile function that can do the task of both hide and show
functions. The toggle function is very useful as it uses a single element to hide or
show an HTML element. It can be a great option to give your users both controls
of showing and hiding a specific element. At Moople Web Design Institute, you
can learn more about jQuery functions and other web design elements.
SlideToggle function
Another versatile jQuery function useful for web designing is the Slide Toggle
function. This toggle function works on the selected HTML element for both slide
Up and slide Down functions. It works similarly to the toggle function comprising
the hide and show function. The only difference is that it comprises the work of
slide Up and slide Down. So, the Slide Toggle function can do the work of both
the slide Up and slide Down functions on a selected HTML element during the
sliding of your webpage.
DOM Manipulation:
jQuery simplifies selecting and manipulating HTML elements.
● $("#elementId"): Selects an element by its ID.
● $(".className"): Selects elements by class name.
● $("element"): Selects elements by tag name.
● .hide(): Hides the selected element(s).
● .show(): Shows the selected element(s).
● .slideUp(): Hides the selected element(s) with a slide-up animation.
● .slideDown(): Shows the selected element(s) with a slide-down animation.
● .fadeIn(): Fades in the selected element(s).
● .fadeOut(): Fades out the selected element(s).
Event Handling:
jQuery makes it easy to handle events like clicks, mouseovers, and form
submissions.
● .click(function(){ ... }): Executes a function when an element is clicked.
● .mouseover(function(){ ... }): Executes a function when the mouse
pointer enters an element.
● .submit(function(){ ... }): Executes a function when a form is
submitted.
Animation:
jQuery simplifies creating animations.
● .animate({properties}, duration, callback): Animates CSS properties
of an element.
AJAX:
jQuery simplifies making asynchronous requests to the server.
● .ajax({ ... }): Sends an asynchronous HTTP request.
●
Interactions:
● Draggable: Makes elements draggable.
● Droppable: Allows elements to be dropped onto other elements.
● Resizable: Makes elements resizable.
● Selectable: Allows selecting multiple elements.
● Sortable: Enables items in a list to be sorted.
Widgets:
● Accordion: Displays collapsible content panels.
● Autocomplete: Provides suggestions as the user types.
● Datepicker: Allows users to select dates from a calendar.
● Dialog: Creates modal dialog boxes.
● Tabs: Creates tabbed content areas.
Effects:
● Show/Hide: Controls the visibility of elements with various effects.
● Fade: Fades elements in or out.
● Slide: Slides elements up or down.
●
● jQuery can be used to dynamically modify CSS classes and styles, allowing
for dynamic updates to the UI.
● jQuery can be used in conjunction with CSS media queries to create
responsive designs that adapt to different screen sizes.
●
● Ease of Use: jQuery's concise syntax makes it easy to learn and use.
● Cross-Browser Compatibility: jQuery handles many cross-browser issues.
● Rich Set of Features: jQuery and jQuery UI provide a wide range of
features for UI design.
● Extensive Plugin Library: Many plugins extend jQuery's functionality.
● Active Community: A large and active community provides support
and resources.
UI DESIGNING
Visual Design:
This involves creating the overall look and feel of the interface, including color
palettes, typography, icons, and other visual elements.
Usability:
Ensuring the interface is easy to navigate and understand, with clear
instructions and intuitive interactions.
Interaction Design:
Focusing on how the user interacts with the interface, including elements like
buttons, menus, and feedback mechanisms.
Accessibility:
Making the interface usable for people with disabilities, considering
factors like screen readers and colorblindness. User-Centered Design:
Designing with the user's needs and goals in mind, prioritizing their
experience.
Wireframing:
Creating low-fidelity sketches or layouts to plan the structure of the
interface.
Prototyping:
Building interactive mockups to test the usability and functionality of the
interface.
UI Design Software:
Using tools like Figma, Adobe XD, or Sketch to create and design interfaces
In essence, UI design is about creating a digital product that is not only visually
pleasing but also easy to use and engaging for the end-use