Docsity

Javascript Handwritten Notes, Study notes of Software Development

Partial preview of the text

Download Javascript Handwritten Notes and more Study notes Software Development in PDF only on Docsity!

classmate. Js Variable [75 Glbbal. Yauonle JS Data Types \» JS Operators ie J5 If Statements - J5 Switch - J5_Loop + J§ Function JavaScript Objects Page _| INO, | 1 6 i) 8 3 3 (2 [4 [5 IG Ig JS Object | _J5 Array 199 JS String lou Is_ Date 26 mn I$ Math 23 . 15 Number | 34 wil JS Boolean ane JowaScript BoM i Browser Objects 3% JovaScript Dom classmate Page __— — | | | ——T Jawa Script OOPs ai — |. TS Class 47 —~|__ 38 Object 43 ee | JIS Prototype 54 [ls constructor Method | 55 — | _Js static Method SI o- Is Encapsulation 28 —_ _ JS Inheritance GO .» 15 Polymorphism Gl _JS Abstraction 62 Script Cookies 63 9. JavaScript Events ule) do. Exception Hand ling | BS 4 JavaScript mtsc 4 J5 this Keyword 133 . TS Debugging 35 4 JS Hoisting 36 4 JS Strict Mode 37 4 _Javascri pt Promise 98 i , JS Compare cates lol JavaScript artery. length las I ‘— JavaScript alert () _ {los | —lavaseript em ane por _JoNaScripl Closest { (08 LT avaseeipt continue Statement Tos . JS get Attributelmethod an _ ‘Jawa Script is Wea kly typed language, Where ceptain types Ape. implicit ly. cost java Script iS an Object - Oriented peogramming lary age, Wwhepeyer ib iS also Use 5 Path hep than Using classes. for inheritance. 5. It 15 o lightaleighted Qnd- inteppreted vie G It_i5 a Cose_- Sensitive longuage He JavaScript is supportable in Several Of systems including Windows, MacOS, etc 13% It Provides Qood contro! tothe Uses Over the Web browsers An. 1993 le oar ace Aagiba siviokeckyen doll into. existence. n the year (994, Netscape twas founded _llby Moe Andpeessen. He vealized thet” the Wwe b need- ed to becotne more dynamic. Thus. OQ ‘g/ue language’ was believed to be povided to HIMT to make | web designing easy for desi geammels, a Consequently in 1995. the Company sc asl Brendan Fich. intending “to implement And embed Shem? preogieamming language to the browser But before — Bren Microsystems for adding Java ihtn its Navigator — So thot it CoUld Compete With Microsoft over the Web technologies Onda platforms. Now two lang-— Wages were there : Java and the Scripting lanquage.— Fusthe ic i t Netscape derided 40 gue a similar Yome— to the Scripting language as Jova's. It led to — Jana Seri pt’ || - Tis wan IS. US@d to Create interactive Websites. | |ks mainly used for: ~ 4, chent-- Side. Vatidation. ~ 2, Dynamic clrop- down menus, -3, Displaying date and time, h. Displaying. Pop-Up Windows and dialog boxes, 5. Displaying Clocks etc. JavaScript Example JavaScript example is easy to Code. JavaScript. provicles 3 Places to put the JavaScript Code: Within. body tag. — within head tag and external JavaScript. file. __ Example et fu _ ___ SSeript type = “text / javascript "> es! _____ document. Write (JavaScript is a Simple language”); — _— - oe | | | ____ The Scpipt tag specifies that (we are using Java Script. ______ The text/jovascript is the Content type that provides _ ____ipforpmation to the browser About the data. ______ The document. Write 0 function is used to display dyn— ___amic_Content through JavaScript. We will learn about. document Object in cletajl lates 1, JavaScript Example: Code between the body tag In the above example, we hove displayed the dyh- amic Content Using JavaScript. Lets See the Simple exa- mple of JavaScript that. displays alert dialog box. | hee | CE 0 ——~ pk external tavascript File must be saved by: | ps ea, ~__—-nsion._It_i5_recommended_to_€mbed—all_JavaScript files __\nto_a__Single File. lt increase _ the. speed. of theuetfne, fl Lebts Oweabe om vextewnnl: joneSopit ~~ _ message. js__ a a ~~ | function msg (\§ ~ alert ("Hello Jovapoint"); huh toHlon, Meta Sek uth Sal eee otters gn at ole Let's include the JovaScript file into html ____-page_It_calls_the _ JavaScript function ee oe crea) | a OW enc Sens ___indexshtmi ale siti AT Fes — Shtm) > es ib tee : oe Shead> ___, __. $ Scipt type = "text pvasonat”se # message. 8° > lsc? ___| = < body > ay ol pe etna 4p lnshSornt Sian:
[Pe pe baat” ‘value = “Click” Onclick = msg [> _____€ 1 form > _ 4d | WIND Jofe@sa yp ee |Z | 2/htmi> ai sites 5 3) me re helps in the Yvesuability of Code in- more than _ p__lOne HTML File. ee aoe f LS | 2 It _allows easy code ya Readability. 3. |t_15 time-efficient OS Web browsers Cache the external | __Js_ files, Which further reduces the Page loading time. as — | __6 lasstnat | rd ) Date ~~ | Qe fase er. lt enables both Web designers and_-Coders to Luo, . With him! and_js files parallely ind Separately, ie, "Without. facing any code Conflictions.— 5. The length of the Code Weduces as Only We nee to Specify the location of the js file... 1. The Stealee may download the Coders Code ugj the Url of the js file. 2..1F two js files are dependent on one nother then -.O failuve_in_one file may apfect the execittion of the other dependent file. == ae, 3. The Web browser needs to make an Odditinal —-http request to get the js code. 4. A tiny to_a_large change _in_ the js Code may _ _— Cause _Unexpected results in all its dependent files. .—_5. We_need to check each file that depends on the ee Commonly Created external javascript file. ____6.If it iS a fet lines of code, then better to _ _ __Implement the _iinternal_javagceipt Code. Mt. a chi C oe —_ Pines | -The_Jovia Script Comments ave meaningful way ] — to_deliver message. |t is used to add infor- _ -Mation. about the code, Warnings or Sugg- CStions . SO. that end User Con easily interpret _ the Code... | The JavaScript. Comment is. ignored by the _JovaScript engine i.e. embedded in the browser. There are mainly two advartages of JS comments. — [Gagan loro amsable | JovaScript tocol Nariable- thin the function Ch L ble_W _ re function. t—i5- _accessi : __ block. Only ——— "elma. —— oe —— | < script > . _ joey Punekion obe tl) ee var x = 40;:// local Variable cherie Soe wih = LL 4 sa a ____-Pmetion._A Viwiable i. declared outside the functin op declared_with lindow object is know a8 global _ _\Noviahle < Script > Nar data = 2005 // global Vaviable ] function allt , /.___ JavaScript Data Types. aah __4 _____ JavaScript _ provides different data types to hald_ ____ different types of Values . There are two types — Of data types in SovinSenjpt sal Primitive? data: type oii) feeds Ft ey -—__2..Non = primitive datatype Mapas ‘ho i/[holding number vet Sh alee Mar b= "Rahal // holding string Sate igal, Sd {i | yin ' a Data Type | Description string Number Boolean lUnderfined | Aull Pepresents Sequence oF characterseg."hello” Pepresents Numeric Values e.g, 100 Pepresents boolean Value either False ortrue Pepresents Undefined Value Pepresents | null iG. no Value at all — | Data Type Description Object Arr ay represents instance through Which We Can access members Yepresents 9roup Of Similar Values Pepresents Regular expression _| _ |Reg Exp 1, JovaScript Operators are. symbols. that are used to. perform Operations On operands. | Licscsenibt uthmetic Opmatans | Arithmetic operators are Used to perform arithmetic. ‘operations on: the operands. Operator |Description Example | + Addition | 10 +20= #0 | tydl ey Fatal tateye Subtraction — 2.0:5-40.,= 40... | ® ~“|Muttiplication | 40*20 = at / Division 20/10 = te Modulus 20 % 10. = = 7 | ++ Increment |vara=:10;atti Now Qazi ee Decrement Var q@ =10 ;Q--) Nowas 9 & se: following Operators are known.as ‘JavaSexigt. Assignment operators Operator Description Exam ple | | = __|Assigh lorlo=20__ | a t= —_ |Add and assigh Wara=i0;Q+=20;NOWa=30 | a = Subtractand assigh |Vora=20;0-=10; Nowa=io _ | = Multiply and assign Nara=lojo"= 20; Now A200 ff ve Divide and assign Nara=!0; a/= 2;NowQ=5 —. L r= [Modulus and aS8igh Vara = 10; 2 %=2 Now a=0 > lava Script _Specia| Operators — __The following Operators are knoninas JovaSaspt Special operators Operator Description | @) sf onditional_ Operator returns Value based on _ a _|the Condition. |t_is like W- else. | ss Comma Operator allows ; multiple ¢ expressions | to be evoluated as Single Statement. delete Delete Operator deletes a property from | ee the object. _ a L. in {In Opetratore Checks if object ‘has the given | [ Lt _jProperty. | ae | | instanceof _ _|Checks if the object is an ‘instence of sien L i _ _|type = | new _ | Creates an instance ig ty - _____ | typeof _ _|Checks the type of Ob ject ) ep _| Noid. lit discards the expression’s return Value. fp yield “checks Whe is returned in Q. generator —— by the generator’s interator. a (ssa rece I~ Si j - el | The _ JavaScript if-else Statement iS Used t oy execute the code \dhether Condition is true ot ‘false. There are three forms of if Statement in ie: 4. If Statement = DINE - else statement —__ 3 pe else \f statement - —— It evaluates the Content only if expression is true. False ~ —_ Condition, _ | : — ] _ | Thue - if#—code: | “f - Prtter 4+ — i Lt. eens | _ | A lf : __, — _-——___ Javascript Switch i s The Janiascript Switch Statement iS Used to execut = ‘One_Code from multiple expressions _ = S Scjipt > = Var grade = ‘B's —_ - _ Var result; - _—_____ Switch (grade) § J Case ‘AN = eect! eel - _Pesult ="AGeadey; breaks _ ft @OGE Busine so Oe Ati we see tt | Pesuit-e "BGrode’; id __|| break : : Wee _|| Case C’; wien | result = "C Grade” _— _ break; ue a _RauMi ot ig eh ic = result =." _ document. Write (resuit); _ ao for (j= t5i< = 5; i+ +) Di sf. ! —_ — Re = on a brie") a a ee _ BR. . <1 scpipt > | Bdesascriet able loop The JonaScript. while loop. ‘iterates the. elements. for the. Infinite Number of times ._ \t_ Should be used i number _ Of itepation is not knoWn.. ——_Bivantage_of JanSargt_ function ___ diGede peusabiliy 27s syste vil ; ——2, Less_Coding ——__ UM at ale bef seme “_ JovoScvipt- _Function. Example _ oo _ |e < Script > _ aide afl eatet ihe nt ___. function_msg,() 10) eet | ilewt ("hello | thie ie nmesee neo eo — A) re ____ <1 sepipt > a _ Output Call function T ly We Can Call function by Passing arguments _Example _ | function getcube (number) 3 | qu (number™® number* number); “ Ss, i —t a os a _Sinput type = . “button” = “click” onclick =" ian 4y"/>_ —} pee, Side eh ~~ Output. yac.atlices = aids — : He all ~ovasennl_ Fucion chert n JovoSeript ,-the purpose of Function Constructor is_ CASSmate (eB to cheate —ae new Function — jee ther ___|the Code globally. However, if NW eeccked-aion | Constructor divectly,.o function 1S dyna. ; ‘mically but in an_unsecureed Wy i et ~—__Juvoeript_ Function Methods Desgription $$. — Taooiyt i is Hal ; 40 Call_o function contains | this Value and a Single. array of arguments. — j Jobing it is used to create o ner Function. | Call () It is Used to Calla function Contains | _ iz this value and an Qbgument list. | _-___|to Stringl) —_||t returns the result ino form of = ___|Q String. ee jj | a ! - SSChjpt> ~~. Mar add =new Function (“humt" "hum", “peturnnumitnum2"); --_» ___ document..lpite lin Cadd (2.59); - Output ~-_JoniaScript Objects SEEnEEeeE ~~. + JavaScript_i5 an object wis... --_,is an abject. in "mlescr gt ee language. Eventing --_____ JavaScript is template basednot cine. to 4 ~~ le don't. Create class " he Class --___._.__ divect. Create objects.