You are on page 1of 8

Jaya Seript

PICT, PUNE

Q1-AErplain the syntax of Javalript funchion wh example


Ela borate dvarntag er of functions.
a follovo
A ng The syntax of a
Jaralcript functho nis
function funchon Name Cparamefes)
code do be execute
Yetu rn relu t ohtonal
de cdare ufunefior in
ca

OEunction Thi keyooyd is edto


day alcript
is the a me ot the funchon H
shoul
Aunioname Tis
be a valididentherCeg no spoce and +
should

folloonaming co nyohtians) Tts used to all the


funchon
Opea meter'sThe are ophional coMMa Separat aue
hat the fuoction con dccept a
input Yàu can
think of them all placholde rs Abr valael youcound
do cthinthe function
return reult ThisJine isophonaf incl aded. H
Spaciher the waluel fhat thenfunchon eturn Ohen

its caled A
Ainctiontan wefusn value,qnd this
alue can
b sed in otheY parts of your code.
Example funcfion add (ab)
Yeturn qtb

Calting the func hon


Nar Sam add (3.5)
console da Csum)

O
Madularty - n chiond lo o you to break youy code
into piec e} you
Jnaler reUlable This makes code
easier to mainduin and under stand
PUNE

T,
PICT, PUNE

Once yo
Jefned a tunction. yo
Reusabilit
can
Wse
it maliple timeswth cifferent inpts,
code
Yedu cing otion
dupliç
-tngdnizcd
Dehugging Fanchion å crecte oel
| Improvid
ode blocks ho a
ealier to debuq and test indepenoe

Creote chijecfs uth example


Ans A
Jayaf cript object data type thet
is q conmpo site
allo to stoye
a collecti on_of key- value pei Y).
where each ket niqjueidentifier ( sually a tig
ard cach saae can he of any data type, incuding
ther abiects ohjects dhe wed to repredent omplec
data stuctures and are a tandanental
do &
Ty ped or wnys cveade objects th exámple
object uith EteralNototion i
&
tOu can create object ing carlybraces f3
deining ts propertied andi vauesthin the broce
Cont person=
frstNameiJphn
ladtName; Doe'.
ge 3o
3
onstrutor Functish -
Can
ehreade obiects by dohining a conshructar
funetion adnd inghe ne
keylord to insfantute
ohjects buded on that con struetoy
fune fion Rrion ( firstNanelatname..aqe
=
HhisfrstName frstName
hisJastName =JastName
thisage =afe,
,PUNE

Facaxy Runchion A
fatory tunchion is a fenction
retum an way to ehcapsulae object
thod object II
ereioh
funchion Create Persen CArttName, Jastna.me, age)
i
return
frstNanme
last Name

qreetunctionc£
consoleJot CHelloa, my name is thi
ArstName
L.

const person Create Perton ( John', 'poe', go),


EnJist Jayascript nth methods and Preict el pechye oudpui
Cany dQo in bniep)
FAnt retuxns e yrdndom
0'math xandam)': This method floahirg
o
point rumher (anclusive) and 1 (oslusive)
hetüeen
Dediction :
co nst random value = Math randomC);
Console. Jag Crandom Value):
I Exampleutputo22 42 5929 3547203 2

thfloorC)' The mathflo or C)' methorounds a

namber doson to the earejf integer


Prodiction
const number s
7-93
=
const ounded Deun mthtoor(Aumber
console Jog (rounded Do.n)
Ilo utput7
aNNa

PICT, PUNE

moth:sqyt () colculte the square


'math:srt)
of a number
Pred iction
Cohstnum l6
Const square Root math sqrt (num)
Concole dag CsquareRoot);

x
G) math po LoCy' mathpo (x) ises do the

cOnst base = 2
const expo nent = 3

onst relult mth poo (h aexponent)


(resu H)
eonsoledog
llo utp ut
a
feûi afthenahy moh rethod!
These arejti
available in Tayas cript The cactaal outot of hele
methods depends on
4hevaled
the youipofs al
arguments in Code
br the specithc Cade

Q2- Explain the concept of Reqular Expxelsiond


and Tdontfy jt dimitatond
it neceesity

And Regdlar Expresition. ofter abbreviatedl af or regekp


rex
dre
poco
orfl patterns wed for pattern mttching
u
within frings They are fandamen fal dool in fext
and Hexihle
processingproviding concise
search extrot and manipalte tertel d ta. Rejulay
espressio clre Japportad
JanguageA includinq TalCripf Pythoa RPeayL.
&
,PUNE

Necesity of Regular Expresiond la


madching & Reqularexp re3iondallos gou cto
detine psHemi do
foarch for and manipulate cathin
toxt data Th' ii _essentid for tosks likedata validtio.,
Searching and text precessing
Text make iH easy
O
Exraction Reqular ospreaiong
do xtract ipecitic Jata frcm text, such a
adtreses) phone humber or OsORL S
Q Dato yalid hion - They are Coomonly ucd to val idte
input dta ensuning adherel to a specitc fornd or
strueture
it
) Text manipathion
replace, moddy sY
Reqal ay expres
eformot
stiand
expresstang ah be
text, making them
eo
inidaablefor tas ks ike data cleaning ortyausfomabng
imitaian cf Requla Expressis nd i
0 Compleuty Aribng and undesdandiy cemplex
ca
egular Ekpres iond car he
he
chaengingLong
chah eng ard
pofernd (an be co me
hard to read and
maintain
9 Perfarfmanc e Reg
Reg uar
dar expresiond
exprension Can he skco ahen
processing-darge
complex
de t. epecially the patem is
O
Lack of Contet Aoare ners Rqular erpresioN coork
Solely baed podterhd and don't under stamd the
contaxt ef thefext.
QPorla bily Regex patterng. vary hetagent
p rogramming anguaq ej and implementations
pottern thct oorks. One danguage might hed
modtication for e in Qnether
A Y6A PUNE

t,
PIGT, PUNE

O.-6 Explain in deulL he ReyixpprotoypT


Jyhtar and exampl
methad Java Soript
of ith is
methad in JayogCript
The Reg Exp. pratatype to String
a
()'
ded to retum aa tring Yeprelentothon of
expres 'bn ohject. Thus brethod is typically i aa
inplicity cohon
hy
Jiecty by develepers but is called
by
coerced into
eqular epressionis
a string Cez
stving c) )
ing
Her the syntax for RegExp protory pedosfringl
- cbject you côast fo
vegex The regular erpression
Convert do CA

const pattern =/4di2,4slgi Regular exres sion.


to match do 2
digits
consale.Jag ceathen totig) tlondpt
Ia this ekample
reulay eKpression /\dil,43L
to 64
22
tohichactchef COhs ecathye
and hal
dho glohal
on padter
Whenthe CalloSfo hingc) the gular
ekpress isn oh;et, it refui dhe ring
cahich is fhe veqular xpre3ion patlern drd its

Q-g-d a. Apply
foloaing ring methodd on
Expresíon ir Tavatript
Reqular Expressioh i= " SCTR? PICT
Pane"
f seach C)
4FUNE

o3. yeplace 0.

replao e)
uth Sub expressiog
Ans. Let's app string methods to the
thepecitied SCTR
given regular eprersion PTCT Aune"
Cohst text =" ScTR'S PICT Pune
const egex
=
PIC T/ [ Requlay xpressioh
madch

f. search C)
a
The isearchc)' method' metho iS (wed to sedych for
Jpecihed Sahstzing or reqalar expression in a
F returnd the ind ex of the frst otcunmenc e af
Hhe hatch is found
=
ionst index fexf Sea rch Creqex )i
consoleJoy ( index); l ootp : (the indox cohere
"PICT is found)

2. Jplit):
an.
The splitC) method i csed do split a string into
apray of sthstrings haed on a specifedsepavaor
(cohich can be a regular expresi'an)
Const ports =
texf Jplit(); spli+ by dhe
and space
Console.Jag Cparts) loutp ut : C"scTRS PTC
fun e"3

3. eplace)
The 'replace()! meffhod to replaoe Substrirg or
i aod
Yegular cxpressionj uth a specihed Sting Jou

also we gubexpressiond Ccapturing groups. in the


eplaeement
hing
PICT, PUNE

Constreplace Text =toxt neplace C/(ScrR') PICT, L,$L


Coilege,D; Using a Sukexresis
Consele dog (repace Text), llodpt scIR'S College
Pune!
In the example aboyeg

In 4he
Sing an
split (, )' Splits t#he sting ito
COmma
padts
xeplate (/ScTR'S) PICT 3
Callege,)' usel a
Suhexpress ion to capturescTRS" and replaces t
SCTR'S coleg e in ahe eting

You might also like