0% found this document useful (0 votes)
6 views43 pages

notes 2

The document provides an overview of variables in JavaScript, including how to declare them using 'var', 'let', and 'const', as well as the rules for naming identifiers. It also covers data types, control statements, and operators, explaining the differences between primitive and non-primitive types, and detailing various looping and decision-making structures. Additionally, it discusses the concept of type conversion and the importance of understanding JavaScript's loosely typed nature.

Uploaded by

nandulap2023
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
6 views43 pages

notes 2

The document provides an overview of variables in JavaScript, including how to declare them using 'var', 'let', and 'const', as well as the rules for naming identifiers. It also covers data types, control statements, and operators, explaining the differences between primitive and non-primitive types, and detailing various looping and decision-making structures. Additionally, it discusses the concept of type conversion and the importance of understanding JavaScript's loosely typed nature.

Uploaded by

nandulap2023
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 43
Vasyiableo + Voxiables ane the memory block iN which we Atove the value of te desta. byppeo . +To wdeclaye voriables %n javascript we une three heyiwords . 2. Van 2» Leb 3. Const ee . _ 4. Von Keyword + “e Allows uv cto declare the Von? able, initialize the volur, Ye-initialize the value and “Retleclane -the vaniable . eq t- Von % ly declaration L=10 Hi Tnitializatlon console. Log (x) dt 10 Mea I Reinttialization console. Log) 4 vo 3% I Redeclaration L%=Q0 console - log Cx) Hao. Note: We hould not sjedeclage , ince we already have & vooi Wale do Atore,n& need do waate the mernorty. » At une Redeclaratfon uring. yan keapwor L ty doesn't Apo OM ON but Ft 1B waste of memory. a. Wet Keyword. + : Allows ub to declaye , tnittalize ond and oeinitfatize dane Vayfable . which %% We can't oe- declaye the vantable valyjeadsy daclajned , ct Leady do evre. eq let % 1 deca ation L210 It Initialization Conpole .log(x) # 10 initialization 0 nee, Vat console « log (a) 4a Redeclanoction let x => er7or Van % => ertor . 3. Const: At quews 4 de decane and initialize thu» Norfable in Aame Line. And we Can't Reintttatization) qedeclaation using. Comet keyword. ey i «Const %x=40 Congole « Log OO #20 Tedentipion + Tdentifiervs din the name the meme block Sk de ued to identity the memoouy- block . + Tdensifie) can be name of vontable , -{onctten, method. anda, clars . Rul» of idendifiens 1. Keyword hould not be an tdenti-fiey. g. identifier howd net start with the Numbers 3. Identifier Should not have a Space. » Wentifier Arould net have speciat characters 4 vounol- opereckers expect fand — . Cavs te deb th =H dt | no keyword: a. let 12%=16 #1! ne nomber 3. det favaseript="" 44] ne space ay. let ab#o=3 Ff lne spactal chat. Note Von?able names Ahould be in Loweycane Catd.) Keywords . d, words wor syeseaved- word rdy ae predepine snot ove having i. a Apecipic pustpere 1h the a “hogy: “Thay aye 63 Keywords . oaloslacas. Data types Datatype ws nothing but a “type of value shied, Can be kept fn the memoauy « Thee one & bypes I. paimitive a. Non- pouimitive . 1 Patimitive datatypes. These age pore defin eck and. Immutable . “They, ane 1. Number &. Boolean ae String 4. Nu 5 5 Undefined & Non primitive These aye userdefined. and. mutable “They are 1 object 2: Avy 3. Function 4.Numbey datatybe In Javascript ak athe numeric tbe of data ub woe Numbex dota type . Since the datatypes aye decided auntn the gnttme tn exden de check what type of data ut dn we une Eype of" operate let %=4 Compote . log (x) #4 Console . Loe (typeo| 2) Numb let xc=4 or Console + dog (x5 typeof x) Type c i Process of Convert one datatype bo another datatyp Ie Implicit 2. Explictt 4. Implictt 4t is the process of Converting. from one data type to another data. “type Tenplictty. with the intervention of the programmer. eqr Console. Loy ( i+ true) ta Because true yalte ‘ig Boolean Syve 1§ converted into Numben 4 Tenplter tly by interpreter EE EE EEA AAEM SU VEU UU UU UGUUUOUDUOUUOUOOEEO OOOO a. Explicit - “dt 4s converting rem one datatybe sto Gantthen datatype by the Programmer acceding. to -the Nequinement 1 Catted Explicit - i det Y= Numben('2') Console . Log-(y » typeof y) #2 ‘nomben! + Boolean datodiype Toe and -faloe saeporenent boolean databype ~ let bool =obre console « Log. (boot typeof boot) lee d= Boolean(s) # type carting console . bog (a) 3. Undefined + When O@ vani able with o value or data, datatype % declaned but not tnitialize vf the vontable would be ond + When the variable Js not nitiatized -then -the vVayTable Value dy undefined and since the value ?% undefined » dakakybe 73 alee undefined. . Ge let % conale - log- oO) Ff undefined. comale. Log (typeof) Mondefined Note: not defined 2 when the varrable in not declaned- % we print om, acer that variable gt 1@ not dulined. 2a: y % console. log-(p) # error z not defined value of P. 4. Nu NW ds © value which van be aasigned into a Nosjiable to make the memosty empty « When the Voovfable value ig null type of that variable TG object ' cia Let cay= “none" Console -log.C car , sbype OF cov) ff neno ee Cam= nwt . Gonsole. Log. Ccar -typeot Cav) # nwt Object 03/05/9035. 5. Strings. decta. ‘type. collection of chovactere , Created + String. 1G a using ‘t and ss . “et we have alphabets, spaces , + within the * "or numbers , Special characters ute., eaouy thing acts ay the chospctors . ° with have index fositions , whee eve chon acten ‘de owing vor unique Tdentity , dt ptarts ffm 0 and ends at Jungth the string -1 “Eq: let $= “javascript” Cornole. Logs , typeoF 8) 4 indexing console .tog-($ Co) Comoe . log (s (33) 1 Length console » Jor (“length s.length) Wl no: of Chane na Ping ts Immutable ceeeaeencnee inl Comote «loa (5) tno change ae Javaseript Storing methods (string bufte-tn rnethod) let muyname="fohn ds qos" Console bog (myname « toUpperCaseC)) # JOHN '8 GooD Comoe . Lo Crqname + charAt (1)) #0 Console + Log: (myname . Comat ("doe") # john is good. doe Console . Joge(myname sincludes ( 'o')) te Troe Console . Jdog-(mi Iname . indexOF ('h')) nae Console . Log (myname. replace (“j',"I") #Tohn ts good. M3 Convercting Adsing. to aoeay, by using. split CD Console» Log-Cmuname . split ()) #C ‘string J Console - Log C myname. split ("")) ae[‘ehar', ‘chav’, ‘chav’ |] Console . Log (myname « spite (' ')) 4 C'word', ‘word’, ‘word 'J Slicing > Extracting. ve part of string using index. A slicing Console -log- (myname -sltce (0,4) 4 John Gnmek. dog (myname - Slice ( 3)) tt gook Strin ‘interpolation ceript voniables 1 ts the procens of using F 07, exprersiors in ; \ me achieve Abting- interpolation by ustry- packtichs and $f 5 javo- eq let X=4 let yea Congote . log. (sum of {ud and bEy3 16 pouty) Control statements flow of executlen here are ued to control the of a ‘Tolman Theye one @ byper. 4. Decision maki statement 2. Looping Statement. 4. Decision makin stakement - —ghese vatatement controls the ~2xecutfon flow bared on the boolean True or False Shey ore \. Tf. g. YH Ore 9. a Use 1 if else ladilen ho Nested tf 5. Switch Care dhe condition tp tyve 1.1 af block ercecrites only when Bap Sypeor* if Cconditton) § block 3 qe af (19<-10) f Console - log (" condition 78 true") a. i} clye “if condition un alee, else block wi ge executter +kbse block ds eclependent block , dependended on ff bloc) Syrians bloc) 44 Ccondition) § block. y lee § j eq: th (ao >= of console - log (“ Condition ds true") ise console . Log Cc" Condition ds foe) 5 3. if thee fh ladder -we use Uae If ladder to check more thon one condition - we can write to number Conditions but ont one padin|ied. condition block would be executed SiR if Cconditiond £ block - ct Cconditiona)é block § abe g block 4 w let marks = 89 ty} (moots >= 85 #44 manks< =100) f Console - Log ("At grade") uge if (marks s=60 44 most <85)f , Console « Log ("8 qrade") wboe Sf Cmasiks S=50 44 manks < 60) 8 console. log (que qrode") alse f console « log (" Fait") 5 . Nested if Jf we waite 4 block inside vanethen # block to heck othe cbtpemelenct wonditions , dk dy wa nested Jf Syntan ¢ ci (condition) § block a (condition) § W nested. a block 4 5 eq let x=4 ik (x70) é comsole .Lon (x, “fs positive”) Hh (~ra==o)t connote. log: (x, "Us even") j o5]05] 9025 5 Switch Case - dt ts used clo check muttiple conditions by matching, the Carer. 4 4 el} dt ds wed any can atten naive ladder to chuck more than one switch CKey) { Saprzar Case value? Statement byeak cane value: Statement byjeak cose value ! statement break def att 1 statement brea $ let oge= 18 suittch Cage) é Care 48% console . loc ( “age tp “ sage) by cak Cane 19 + Console «log Cr age 18", age) boeak Case Qo: Console « tog C Oge up in" age) bayeak dle} cust : compote « Log (* no matching age a + Book: Boeak hegword. Atops execution once any LODE ap cela Q. Looping Statements. + dhere are und to execute a block of code. nepeadedly until the condition %@ “piss “looping stoternents qenerouny executes the blocks @ infinite Himes, vor» pregrammen buy athe i vwe con steuminate the — Loop to Perform Gorme tak. “In Jove seript there ae 5 Loopg : \. For loop Q. While Loop 3. Do while Loop A. for of — loop 5. {or in loop 1. Fer Suntan + {er Cintbializatton ; condttfon 5 opdakronyé block of Code j Tncrementob Loops romple x or ( Let Wels Xea5s et S Console « Log (x) 5 Decrvemental doo exomple : er let 25; Y>=43 H--DE console . tog (1) 3 &. While loop Syntax t initializatfon while(conditfon) £ bloch vf code updation 5. Tncrementoal boop example let x=4 while (x<=5) € Console + Log (7%) Do+t 5 Decremertal Loop exarnple let z=5 while (z >= 8 Console - log. Ce) z-- 5 4 Do-ushile Loop. Syma + anibiali zaction dos block of Code Updasion 3 while ( condition ) I \ do while Loop atleast executes once even 4" Gnvalicl condition. ty i let ~m=2 dos console - Log. (x) +t ¢ 3 whtle (<= 5) 4. Fo me oe alternative loop -for logtcat fer Loop 5 we don't peed sto anatte omy omdittons to termPnate the Loop — ce Loop “Can be une apfictercey te work with the objects Liks ssbetnge , linty and. objects Syntani- ism (let vastable of collection) { block. > cole 4 I coltsxkT 9 — Scbing. , OrTaHy’> (Ga objects § Key 2 vetiue tet str=" Laptop" for (const 2 for str) § Console - Joy od $ M\ 6 stepoererct, -Uuuuy cha octer af string . 5. Foo in boop + dt van be vopp lied. on atrings and. arnaxys mot on the objec. + fpr tn loop provider rindeniing:: Syrtbar 3 40" Cconat kop tn objects ) § block ef code 4 let Str = “Laptop” for Const 1 tm str) é Console . log. Cstrlty) /s Index 5 oslos/s0 as Operates. re soperator 7@ a pte- defined symbol ured. perform operations on the operands - + Mainly thee are 3 capper of operators 1. Unary operators ( only a operon 3) 8. Binary operates Ca operands) 3. Ternary operasters( more -than Q operands) + Binosuy operators + 1. Arithmetic operators (+,~, KJ, x) 2. Assignment operate t Sheje ane 2 > 1. Single assignment Operator (>) 9. Compound avssignment Operator (+=, -=, ee, f=, A= vee), 3. Relational operators (>34, > eS) Lenn nn nD DH HCKLAAAAARHARARATEBSESHKEEAN wr Logical operators (KA , IIL) 5. Bitwise operators (1, , a, ce 5>>). | Q. Unowy- Operator 2. Sncrement operate C++) &. Decrunent Operator c--) oe Tern ay Operator . Conditional Operatton + yar s— (Condition) 7 Statement 4 + Statement 2 1. Avithmetic operator: . W+ > At Perfosims cttw tarky addition amd. Loratenation Comole dog C4 +4.2) #Q.a Console - Jog (44+"Abe") a 1Abe contol. bog. (4 + “10") 4p 240 Console - Jog (tre +1) #28 Conbole. - fog. (muh+4) #4 Console . Log (undagined. +4) # Nan- not va numbe . I] | - -> Subshiacien Cornele slog C24) Conrole . Log-(False - 1.) Comole . tog “abe"-40) |f Nam Console. log-( "10" - 5) Ib Loosely typed. in nokwie. Console..tog ("a"—"4") jo Note:tApart trom + Operator att the othes -operectey wish Consioen Abing Dype number as a puye rember X Tova seript %§ loosely. AYped in netuye , tam Uke Tava , Python, c, C+4 ane abitotly. typed fn Notuyge. eS Muti plication operator . Console -loa (ax 3) 16 Conbote Loy Cae *3") "6 Console. Log. C'abe" x a) INom / > quottent operator. console + Loy Clo 15) Ne console log (10"/s Ile ‘h 7 TemMaindey Console «Log. ( 10 4 3) "a ts gjemainder Conbole .Log- C10" #3) Axx =z power Console -Log( 2¥¥3) 8 Comsole . Log Ca wus") 1B » Assignment Operator 4aample fon Ainge and compounst anntgnment operation det %= 4 Console . Log. (*) I Compount vasniqnmant : wtet WA WHEL Console . log (~) pres Whee a-4 corel, . Log OO a x2 10 Wi x2 #10 Console. hog CX) FRIFVIVSVVIVVSVVVV VEU UVVUUUUOOUOUOWKOOObdddddddddda 1210 It w= % 9/40 Compete « bog. Cx) wee = 3 Hts tN Console . bog cx) 3. Relational Operators: i output hese operators yet boolean outp. rr Uet wee 4 le eee console . tog L* 4) Console. tog (7 ae corveale log (% > =) fF Tre Consol. Log (a >=a) A fe Console -tog- (%<4) 4b False console. fog, (% = 4) Ht Tyve console «leg (10 >“ 5") af Tree. Consele. tog (4o= =~" obo") # Fake conrole « hoy (10 = = to) 4 Tyve console . doa-(10 “10") 4 Tree J compos valuey Console . Loy 10 = “lo") Fale 1 Comparer values amd deca. Fypes Contele. bog (44> 10) Comrole . Joy (10 b= "10) 4F False Gols. Jog(s0 $=="10") #Tve OF(09/c02-9 We Logical operactor a. && And operator need au the Aattinfid to provide ayve output. er & ip UP Op conditiens to be T T T TIFF Fitfie FUF] FI ai Console .loq( true £4 true) rte Console . log ( pore Ad true) A false Corvsole - Loy (40 ==10 242 a>1) tetrve all > operator need B amy one conditien do be Actinfied to provide the dye output . tip ip oP ee FH AI E Ey: Console. Lo (tell tree) — #Ftwe (false tree) # troe (false Il fatse) 4 fatoc (40==10 | 224) te tyve a|aljal a > |a\n 4 3- | operator Th the Toput Te ve Vice vexga. t/p elp TIF L F|t console. log (| twe) console . Log Cb 4A*) console. Loy ( $4) console « fog Cho) 44° 2. Unasuy openactors heje aye 2 types 1. Tnevement (++) Q-Deesernent (--) Pre -tnevernent pet met console. Loy (44%) acta Pre - ducnement let Z=3 eh getwins aloe amd fate dt true 4 foe 4 true a Console tog (@--2) 2 Post - increment let Yea Consol. Log. ( y ++) Na Console . dog ( y ) ie Post - decrement lek a=3 Cons ale - boy Ca. -~) #3 Gmbole. log Ca) a 3 “Teinosuy. Operator . Ih the condition 7@ t1ve stakem treated , 2 falre Ataterment two with execute. _ emk one will be ty let masdy = 35 n tes,, Let gesubt = (mank >= 30)?" Pars" 2 Yat console - Log ( 9] eoute) # foil . Tmposjtant Lnteyview Bverstions 2, What J» JavaScript 2 Explasn the poawje 2. JavaScript 1s introduced fn which year by uohem 2 3. What 6 ECMA sesipt ? 4. What 16 difference blur Tava and Javaseript ? 5. Diperence blw pythen amd Tava suript . 6. What oie Identifies amd the gules of identifiers By Dillenence blw Vor , Let ond const e. What age dada Whe? Explain primttive and non-primtdive data, types *§ pifleence Bur nutt and undepined 10. Difference blur undefined amd not defined ML. Explain alt tthe Tova. seript Operakong . thy Dit enence blu == and 13. Explain Loops dn Tovasuipt. 14 Difference bw fen of loop and fe In loop . as Di{fownce Hus -fer and while loop a6 Die Explain Noted f{ amd switch cane, Simple Ppryran \- WAP to Jind the nmumbey 15 even or odd , accept the snput rom the User let = Nomben( prompt (" Enter a number" )) H Cet az=o)f : console . toa-( * $ §xc¥ ds even *) else £ ; Console fog (4424 16 oda) Fonckions . Tt 1§ a block of code aye set of Inshuctions ured to perform ~ specific tok. + Function aye Created by ustng- spunction ary « Fonctton should shave o& name ab Toemttfiin A that we Lan yea the ~functien for execution. + Without walling the block of code wit not be sedge pitas ie M1 crecte function function fun()§ console . L04- (" Helle wortd") a Uf Cow undion fun() Note _ etions ane useful To code aeunability . Aq Ml qonctton with parameters functton add (%,4) f , Compote. bog. (x +4) adel (2,3) M5 adel (“salman" ," Khan") Il Satman Khan adel (2,5,6,7) Wt (tH Te take font two Ongumarts , Sut aze ‘ge. add (4) If Non- « 1g a, but 4 76 on ee at ondetined, = Nan SPVVVVVVVVVVIVVVVVVVERVVVUBUVDUDOUOTHEEESCTIITE o@|os [20265 Retunn Keyword dt de ured to getwin a value from the function to +the function cable. "Returned value can be kept fn a voxiable and red. 46" -furthun operations. or common s Within a Single block * we wan une only one Hetwun Atocement + Retwun Keyword. wan be ured. omy within the function 07] a method. . After the qetunn statement we can't ewoite oo 4 i other statement function fsEvem( num) t a (nom /a= = 0) § gjetunn ‘ Even" 5 let sep= ts Even (6) Console . tog, (*PReoutte te p1e23*) Default Panametesrs . While creating a L We wnian seme obfautt values do dhe function panametey 40 thot vobile vealking- the function even thoogh q we provide less number of angers » AtUL pndion Provides the output “fq: function sum (x=0, ys0, Ze0)f eect Coad Zz) g sum ( 1 4,2 63) tC sum C 199) #3 sem ( 6) HS Sum () we 0g|512025. + While Cojeating Ol fon Wwe axeiqn Aome values to the fonction Panametow 4&, that while calling: the -function even though we Porovide ler 2 of oongumenty Sai function Porovides the output 4 fonetfen fon (a,b,c= 420) § Van b = ‘is! console . Jog Carb, c) 3 fun (* Dingo") Helps Dinga a» 420 cad fonction fon (a,b, C=420) f let b="Fe" y Console. . tog. (a,b,c) fon (*Dinga") ape Tdontifterb' ts adsjeody, declaned . Note:- - let const keyword. cannot be a accept gje- declasjaxion . = Von Keyword. db poretble an both daclaratien and. gediclanation . Genenal / Named. functfon Program -wap do scheck whether given number I6 even O37 odd by using geneva -function with parameten and sjetun volute - + fonction evenOdd Cnom) & if (nvm pa ==0)f etur( num +" 18 even") 7 bee § nean( nom +“ ts odd") 3 let en= evenOdd (go) ofp :- < ; Console . Log Cotes) # O[pi- 20 7B even ¢ fonction evendddCnom)f oreuxn Chum &==0) 7 num + "1S even" : num + "i6 odd" 3 lek oper = even Oald Cao) Console. Log (sven) +to[p i 20 Js odd. ‘Anony mows enction (es6) ge not thee - dn Qnonymouwr fenetion , qenctton name 4% - Complete fon whak to Stoojed Tm veiable. Vaniable we Con -4n anonymow» -{un ction en ‘invoke 09) cat, the fonction . Syntax :- let fun= netion Cparameten 2, Panamneten 2) § /| punetion body g on (ang + ) ang a3... -) Eqi- t let {un = fonction (frm, inn) § Congole - tog. (* Myname ip "+ fnm 4 lnm) 5 let P= jun(* Dinga” , Raja") Console « !o4- (P12) H ofp w- My mame 19 Dingaroja. + let fune function (4rm, Lnm)é sutuan “ Muyname ip" + jnm+ Lom 5 let Pa = fun (“ Binga” + * Raja") console . log CPs) 4rolp: My name 16 Dingo Raja + bet on = yoo ction (4am pinm) & aVeturn “My. name Te" + frm + lnm 3 Let Pie fon(" Dinga”, “Raja’) Conpole- Loy (Ps) Console. Loy Cpe C'Ding", “Rant ‘) # 0/P? My name ip DingaRaja My name te “Dingtkami © Let fun= function (> § J Conpole - cod (fon) #ojper OL 3 Asnow function Ces 6) Symrtox:- C> Indicates — Oa 8 sanction ) Eqi fo fun = eae at aekunn (“ Helo" + Use) 3 fe ve fun (* Dingo) connote . Log (%) 4 olps- tello Dinge. » tet fone Coser) 8 Console - loq- (“ Hello" + vsen) -fon i Dingu") de ofP: Hello Ding dat dune > f Console OS Cor) 5 -for © 4 Ofp- fen «let fon= O98 console - tog: (42%) j Console . log (fur) fofp- ()>¢ console - 109 (fun) 3. Special behaniousr te Lee fun=() > Console .log-C" Hetto\) fon Sn aeemuss function wenlif ome point statement wp dheje flower brace i¢ optional. 2. let num= asdf Console - log Ca) J hom (100) Th aviuow function von. one Panameterize L that panamtheg is db optional and In all othe, Carer Panamthests TE mamdaxory 3. let fun = -=>§ Console. dag (* welcome") J tan) - Th asview fundion ponaméeten ds net uni then pananthesis Te optional Tnatead ef Paviamtheni, We van une _ Cundenscore) Lv heje undenscone 7 acting Uke a porrametes) 4. Let evenddd= nom = (num %2 == 0) 2 num + “1s Even” nom +“ ts odd" Console « Jog (even Odd (g0)) -Tr asvi0ow function oh one a]etunn Stater 4 e ig thene then the > Keroord. anal he braces dn optional - fier oo wlos|27s * Self Tnvoktng fonction CIF) ©) Tmmediately Tovoking- fondion (rr F) ~ These functions clon't need ony identifier to execute them . These -furvctions wan't be vetoed onltke other Lone . — There functions Aphould be cont Tmmedtak i ation 07] definitiin. vaulter the function e54e ef Suntax + (create enction) Coalting- Statement) “4 © [Yoncsion (0.605 { Console . log Cat+b) $) (4,2) 4 olp : 3 Hen procens movin: daclanaktons on top ol jhe stope by the intgpneten ducing. the execution eh program qt dew doe behautoun of hoisting. the interpreter « _ one uso type of hoisting . 4.Voniable hoisbing 2. function hoisting. rolesiro2s. IBZZABBARBARAAABAAMAMMMHHHHHHAHARHKRAKRAKRARAKRARARRERERS 16los|aor5. Method. $n fovascript methods wae caeated. ey clays without using ton Keyword. ee mer Of the \buninn up aimilan to functions. Cajectting. object uning- corotnuctor function. function Cay (name ,Patice) £ cthis -nName=name is. “price = price this. byeaking = fonction CE Console slog (“ boyeak applied") 4 § let Cana. = neur Can ("" Byezza", 'g Lakh") Console whog (cana) Cont. «baeaking () be Cand = news Can (“nane", 4 Latdys' Console « log. ( can a) Cond . breaking ( B) DOM ( Decement objects Methods). Dom -htmL Welcome, to my clams" * onclick =" double click ¢)" > Click heve <| butten> f let oc = document “ge me vinnesttext =" hove Javascript * + Ted 5 background. : yeHou s Elemenct By Td. C* header") q oe. sdyte. cssTeak = Color 4 let double Click = C y>f , xc inneatext = "LT Love React nc. Style « cagtext = ‘colon: pink’ vtlosho2s 5 Dom. html 2div clans = “ Containen"s
button onclick = “ boxDestgn ( 3"> Click hexe. <|button > Dom. Css « containes { disploy- 5 flex; _junttqy-content + space: evenly j 3 -box§ borden : solid, 1p%5 hetgoe + ABOPX ; width + 100 px; Dom. 8 let boxer = getElement By Clansname ( " Box") tet boxdeviqn eat boxes[o) innertext =" welcome" ” bowes [1] - style - background at oed ee: = bonden- radius 2 50 boxesla). sayte - cssText on 3 Changing the Tmagt doc. WtmL / height = "150" width= “150 < ima gree "*/---- . onclick =" change Image ( > doc. js — ler changeTmoge- -Oré let image = docurnerd: gut ElemerceBy Tag-hame.(' img") image[o}. sre = or 4 ONOFE lt onoff =OPE tet bin = docomenk « qrouy- selector ( " 7 btn") Hf (bth. tnnurtext = = = ON’) E btn-TnnenText = ‘OFF! document body .Stife,. background Bee Une f btn. TanerTeact = ‘on' document . body fl style . background. = ‘White’ g doc. html oe zbuston id=“ btn" onclicks * onofti)"> ON <| butt en > Document | htm \ TT head b ody. ee meta = Fite div DOM 18|05)2026 . DOM Atotndy ca Document object modal . Ut us va dace dike mreprenention ef Htmt document whee document 2 to me webpage ound. object nnefeng do we tag. and Model oneferys to tree like mepaepentation . Dom dn javascript i¢ usefat dn Dynamically Met fying: the tag's om a webpage vacconding- to che Usen needs. In onder to sued the tag» they ane fuw “DOM methods:— 4. document + qetElementBy Td O Q. document . gee Element By Clansvame () 3. document - gut Blement By-Taqvame () 4. clocument + gpwuy Suector C) 5. cowment . qua Seecter-AU C) 4. document . getElement Byrd. C) 4k in 22 DOM method. ured. to select a 04, with nee of Td: 9, docurnert - qué Element By Clarsplome) dt dx a Dom method. ured to deloct rowsiple dogs SL same clexs Name. dp getwins oF emt collection of tags Aimiloar Lo Of - 3 Let tags= document « get Elernert’s By ClansName ( a) Console - Jog. (tage) 3 mod.t}uing. sndividwal tag. taqsCo3 “innettext =" Salman" #ernodifying oul tags fon (tet tay of stags) § +04. syle - color =" aek" y Jet dogs = document - ger Elements By Tag ame Cc) console - Log. (409) tage [0] . atsyle. Color =" green " fon ( Let dag 4 toas) { tag. « Able Text Align = “ cede 9 4 <| seript> 4. document « quaruyselector C) 4t dx © Dom method used cto Adlect very, cone tag with aiefenence of an Td Clay 09) Re oer 6. document - Selector AU C) Jt Gn ver DOM method, ured to select wh she tags Bt same Td 0) Same Clard 09] Same —tag-name At getunn Node list of tags Web Tava

< Script > 3 let ckags = document: - qpinvy Selecke AU. (‘b1*) fon (let tag, oy tags) £ tay - Sayle- color =“Yeal ¥ gy <[ Sevipt > oTP vasiclation Qo\os|2025 #4 w- Zousten Th =" gef- otp "> Gek ofp <|budton> ISPPRARBBBAABRABKAABAKHAKBABAARRRRRARRARARRRRRRARRARRRAaRBRRAR Validate <| butten > <|Smau> det btn = document. qt Element By Td. (‘gen- op!) tet foun document -quvuy Selucton C'{forum') let msqiag = document - Jet Element By rd Cimsg’) let muyotp bth -ondick =() Sf Let obp= Math-o1ound (Math. nandem () * 1000) if GbpssaaF alert (* obp ig $fotpz') muyotp = otp he & ofp = Moth: mound (Math. aandem (1 * 41000) : Console. tow C* click aq ein" ) sonsubmit = (e) >$ let Trpuk =e .tonget To] « Value 4 (myotp == otpinput) § maqtag.. InneText = “Otp watidated " msqtag, . Style. colox aigreen® hye § mag tag. ae tonertext =“ tnvalich otp “ msgqtag . Saye ~ color = “sed " } € - prevent default () at dt stops the page spem greload om one} verh, 3 elsonipt> Random Gucter Generator - Zbodiy7 . Zdiv Clam ="Main" > ; Zha > Random Gvoter Genenater ; Generate Gvote <|div>
Zhi ihe"a's L/sin> tes= [ na qpote 1, Jarote 2, 1 let ha = document « Jet ElemenkByrd ("a") Let btn = document qos selector Cc‘ button") btn. ondbletick = 0) >{ tet Yandomtndex= Math. sjoond (Moth. ZJardemf, ) * quotes. length) ha -Tnneitext = sand qotes Caandemindex) 5 <] hem > Calcutettor,
4 9 = <[ buttons ~ <| body > <| htmb> Calei.S let Screen = document . qursuy Selector (input) function getBtnvawele) Screen value + se. tonget + Tonentert 5 function cGsplouy Ot let gjesurt = eval (screen. value) Screen.Value = O]esu& 3 fonction Ac OE Screen. Value =“ " 3 4unction Clean Sev OE Svalue = Streen-Value Screen Value = Svabte . slice(o, value «| -4) j IRPPRARARAAARARARHRAAKRKRKRAKRKHAARKAAARRRRAKRMhKeRKREERE

You might also like