idk Features OT JaVaSCript
[Q. Enlist features of davaScript. a :
JavaScript is an object-based scripting language.
Giving the user more control over the browser.
It Handling dates and time.
It Detecting the user's browser and OS,
> tt is light weighted.
~_lavaSeript is a scripting language and it is not java.avaScriptis inter sd scripting langue
iptis i
's Interpreter based ser ¥
JavaScript is case sensitive iefined 0!
JavaScript is object ie ' age as it provides
ipt is obj
ject based language as it provi :
Every st
tatement i
in javascript must be terminated with semicol
tax of control $
functions withi
jects.
jon (3). ents
in C language.
Most of the javascript control statements synta ES
jpts. Declare a ion
An im
portant part
Part of JavaScript is the ability to create new
JavaScript using function keywor
1g function
ight Weightodarrow functions. We will explore the
syntax and structure of arrow functions,
as well as their advantages. | hope you
enjoy it.
What the "=>" Symbol
Means
The "=>" symbol, also known as the
equals greater than symbol or
hashrocket, is a shorthand notation for
defining functions in JavaScript. It is used
to create a new type of function called an
arrow function.
Arrow functions have a simpler and more
concise syntax than traditional function
expressions. You can use them to define
anonymous functions or to pass
functions as arguments to other
functions.@. Describe how to link banner advertisement to URL with example, =|
[Wi-22, 6 ttaris
@. Develop a JavaScript program to create Rotating Banner Ads.
‘rectangular area in webpage where image is placed for advertisement purpose is known as Banner) Banner
can be placed anywhere in the webpage, horizontally on top and bottom or vertically at right and left side of the
webpage.
6.2.1 Loading and Displaying the Banner Advertisement
To load and display the banner advertisement, we placed an image in website. That image is advertisement of
particular advertiser. We can also provide the link to that image. When image is clicked it will go to the adver tiser's
website.
To ink URL to advertisment we Create,
+o link the current banner image. to th
BRL. |
We ine
o the. hret ae
and
ee
tibuie. ofthen we need to set the attributes
5.2.2 Invisible Borders of Frame
. sible,
Frame gets border by default/ifwe want to set the border ofa frame invisible
“frameborder’ and border’ =O.) 8
‘frameborder’ and ‘border’ =0. ae
Program 5.2.6 : Write a JavaScript to set the invisible bordr of frame
Soin. :
main_frame.htmi
wvigation and web Page Protection
Menus Nay
structure and set of
6-28
‘eript code that provide a
v
v
JavaScript’ frameworks are collections of
guidelines for building web applications. These framewor!
make jt easier to build complex web applica
Following are JavaScript frameworks and their applications :
framework de
‘cd on a component-based architecture, where individual
re-written Javas
7 sovine developers with a set of tools and libraries that
ks provid
tions quickly and efficiently.
React : React is a popular front-end JavaScript wveloped by Facebook. It is used to build user
interfaces (UIs) for web applications. React is bas
Ur eomponents are reusable and can be combined to create complex Interfaces. React Is widely used for
building single-page applications (SPAs) and mobile apps.
JavaScript framework developed by Google. It is used to build complex
ides a powerful set of features for building
Angular : Angular is a front-end J
web applications with a rich user interface, Angular provi
dynamic web applications, including data binding, dependency injection, and modular design.
Vuejs : Vuejs isa front-end JavaScript framework that is similar to React in many ways. Itis designed to be
easy to learn and use, and provides a lightweight, flexible framework for building web applications. Vuejs is
often used for building small to medium-sized applications.
Nodejs : Nodejs is a back-end JavaScript framework that allows developers to build server-side
applications using JavaScript. It provides a powerful set of tools and libraries for building scalable, high-
performance applications. Node/s is often used for building real-time applications, APIs, and web services.
Express,js : Expressjs is a back-end JavaScript framework built on top of Nodejs. It provides a simple, yet
powerful framework for building web applications and APIs. Express,js is often used for building RESTfulROSE.
3.5 Adding an
is important ‘to inct
Array Element
owing are two ways to 208
crease the size of an array b’
yy adding elements Fol
4 changes the original
sometimes,
cof an array. This methor
cjements in an array ~
tho Ie adds one oF more ‘elements at the end
Using push 0 ™
+ ona of an array: )
syntax:
; 2 am. j
ipt code to implement push method of Array.
program 2.1.7 = Write a JavaserltMobiles -
‘Product’ then the side menu items wall be
“Laptops, then the sub menu item of Laptops" vill be displayed,
6.5__Protecting the Webpage
[2 ._List ways of protecting your webpage ana describe any one of them. ieee
6.5.1 (Hiding Your coda :
Bam |
‘he Source code of the webpage can be viewed by clicking right mouse button on the webpage. Anyone who
visits to the webpage can simply view the source code of the webpage. Viewing source code by users is not safe. We
can hide the source code of the webpage by disablin,
2 (Disabting the Right Mouse Button
‘The source code of the webpage of some websites can be viewed by ight clicking and selecting the option ‘view
“source. By viewing source code we can find out how the webpage is created, anyone can use that source code to
create their own webpage. It is not secure to display a source code to users. We can disable the right click of mouse
button. Thus the user cannot see the source code of the webpage.
Program 6.5.1 : Write a JavaScript code to disable the right mouse cick.
Soin.
»
documentaddEventListener(‘contextment
3
sevent=>event preventDefault());ng ueunguaye
Description
Method Name
and returns its posig, ~~
i
jven string
ular expression in a B 3]
It searches a specified regi
match occurs.
; iven string and returns th,
expression in a giv’ egy
It searches a specified regular exp n
expression ifa match occurs.
i icement.
Itreplaces a given string with the specified repla - -
1g on the basis of the specified Starting
substr() It is used to fetch the part of the given strin}
Position and length.
sof the specified index,
7 si
Itis used to fetch the part of the given string on the ba
Ie is used to fetch the part of the given string. It allows us to assign positive as yy)
negative index.
It converts the given string into lowercase letter.
foLocaleLowerCase()
toUpperCaseQ
It converts the given string into lowercase letter on the basis of host?s current locale,
| It converts the given string into uppercase letter.
‘ohocaleUppercaset) | Jt converts the given string into uppercase letter on the basis of host?s current locale,
toString |
Itprovides a string Tepresenting the particular object.
valueOfQ) l
It provides the primitive value of string object.
2 Inininn 02+S@MICOION, DULL a Lane ~~~
"loads" these JavaScript URLs, it execute:
browsers are not allowin|
.s the JavaScript code present Mm war vase wen me -
g, to execute the javascript code in URLs.
security reasons the recent
a6 Javascript Security
( There are several JavaScript security issues that needs to be considered. As a javascript used in dient side, a risk
is there for end users. It enables malicious users to send scripts over the web and run them on client computers.
There are two measures need to be considered. We should use scripts separately so that the malicious users can
only access certain resources and perform specific tasks. The second measure is we should implement the same
origin policy ie. we must use the script from only one site, which prevents scripts of one site from accessing data
from script of other sites. ‘
eee (xss) is one of the most common JavaScript security vulnerabilities. Cross-Site Scripting
malcoug ities allow malicious users i manipulate websites to return malicious scripts to the users. These
nalwarg serps then execute on the client web browser, It can be result in user data theft, account tampering,
Spreading or remote control over a user's browser. : ‘‘L7__Loop Statement
Loops in JavaScript are used to execute the same block of code a specified number of times or while a specified
condition is true. )
Following are the four types of loops in JavaScript.
4.7.1 for Loop2. (Using unshift Q method : It adds one or more elements in the beginning of an array. It returns the updated
array with change in length.)
Syntax:
(array, unshitt(@etient,element2,-yelemeni-n)1.6 _ Switch Case Statement *
The switch-case statement in JavaScript is used for decision making purposes. The switch case statement is @
‘multiway branch statement. It provides an easy way to execution different parts of code based on the value of the
expression,
Syntax :case valuel:
statémentl;
breaks
case value2:
statement2;
break;
case valueN:
statementN;
break;
default:
statementDefault;
j ooClient Side Scripting Language _
5 ath ")
documentorite(“Original Length ="+aenttl
apush("Java");
apush("VB","PHP"); i
document.write(’New Length after push methor
yi
‘
4
Output:
2. (Using unshift () method : It adds one or more elements in. the beginning of an array..It returns the update
array with change in length)
Syntax:
array. unshift(elesenti,clement2,.element-n)
Example :
aunshift("C");
aunshift("C,"C+4"};
Program 2.1.8 : Wit a Javascript code to add elements in aray using unshit method of array
Soln.
title> Array Demo
3
‘
2 TitelThe core of JavaScript is known as
ECMAScript (ES).
ECMAScript is the standardized scripting
language specification upon which
JavaScript is based. It defines the syntax,
types, objects, and the basic features of the
language. JavaScript is an implementation of
ECMAScript, along with additional features
for web browsers and other environments.Client Side Scripting Language
[BRA revivascriptegenrpranenyitot >
SE ® thexypepravas:
In Program 5.1.10, the statement ‘var patt = new RegExp("Hello World”
16
"ji fs used to create an object of Regt,
*Y which search the petaee
nth he ing proved a rt pantheon pete the rif wh Search Oe Pr
global i.e. throughout the text for the occurrences of pattern. The statement ‘var
function that created the RegExp object's prototype.
5.2 Frame
nt to displa}
ITML document can be divided into multiple parts by using frame. if we want to display
ifferent information in
different parts of webpage, then it can be possible by defining that information in a different a By us ame
we can define the multiple views. With the help of multiple views we can keep specific informat on visole whl t
the same time other information will be invisible ie. it may be hide, scrolled or replaced) For example, if we have to
set the title, description, navigation bar; advertisements, contact details and notification séctions in the webpage, then
{itle 1s placed in one frame, description is placed in one frame, navigation bar is placed in one frame, advertisements
Placed in one frame, contact is placed in one frame and notification section is placed in one frame. The multiple
frames can be set in one webpage as follows :
Frame 5.
Fig. 5.2.1: Webpage containing multiple frames
5.2.1 Create a Frame
Co detine a frame we use tag. Each in a