Professional Documents
Culture Documents
Js Ut 2sdsd
Js Ut 2sdsd
PICT, PUNE
its caled A
Ainctiontan wefusn value,qnd this
alue can
b sed in otheY parts of your code.
Example funcfion add (ab)
Yeturn qtb
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
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.
PICT, PUNE
x
G) math po LoCy' mathpo (x) ises do the
cOnst base = 2
const expo nent = 3
t,
PIGT, PUNE
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
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