You are on page 1of 105
Harsha Vardhan (UI Expert) at Ourgasoft Udemy courses at 650 INR htps://www.udemy.com/courses/search/?qsharsha consolelog(temp2);//rue temp3 = (x Yi consolelog( temps); //false temp6 = (x>= yi console log(temp6);/false Il Or (Atleast any one condition should tetrue) ! Not (given condition willbe reverse) Example on Logical Operator shims a ‘chead> Logical operatars -Logical operators e + These areusedto make teen eo aw jmp backward, «© JavaScript supports two Bigs of corfifp| statements: 1 Condona Conv Stitamens Used jump ar a 2. Se “Dag iy Bcivara O i) ft O ‘© “If” statement is used to check a condition, and execute the code only if the condition is TRUE. - Types of “if” ) Lif 2uifelse U F 3.Elseif HTML, CSS, JavaScript, Bootstrap Page s17142 ccecc Harsha Vardhan (Ul Expert) at Durgasoft LUdemy courses at 650 INR - htps://www.udemy.com/courses/search/?q=harsha 4.Nested if Simple If - a \entry if (contition) { Yirue code here false } y aa oxit “titletctile> Sboay> varn 20: if(n == 10) { consoletog(n is equat to 10%; congblesog("n iginotequal tollny, sjscripis beta HTML, CSS, JavaScript, Bootstrap Page s2ilazz Harsha Vardhan (UI Expert) at Durgasoft Udemy courses at 650 INR - htps://www.udemy.com/coursessearch/?q=harsha Else iF entry if (condition) { \fne code here (im / else if (condition) false ; o true } code here { a7 false j | | else | fl code here 1) NN { Y exit Example ofi“else-if- ahead “atitle>eise it thea “nl>elseli/ha> Scrip var a= 10,6220; if(a b) console.tog("a is greater than b’); else console.log(‘s and b are equal’ HTML, CSS, JavaScript, Bootstrap Page 3221422 CA acre Harsha Vardhan (UI Expert) at Durgasoft Udemy courses at 650 INR - htps://www.uudemy.com/courses/search/2qsharsha itm Nested If _ a entry if (condition) © \ ee if (condition) \ false { \irue code here) | ,/_/ | } C / false lew exit Example of “nested if” shims “head> itle>Neste fertile» Sbo> lp “ ¥ vara0, b= 20), 5% consoleog(‘a is less than b*}; alse { consolelog(‘a and b are equal’; ) nim ‘ fl Do-While s 4% > “Done fer on Mat op OO +The dlferenethis: “while” [dbp checks the condition for the first time also; but “do-while” loop doesnt check thondtion or thefist tie, HTML, CSS, JavaScript, Bootstrap Page 3251422 Harsha Vardhan (UI Expert) at Durgasoft Udemy courses at 650 INR -htps://www..udemy.com/courses/search/24=harsha code here } while (condition); true false loop exit Example on Do-While “chimis a chead> -stitlesdo-whilecitie> do-while html ‘Arguments andReturn ba stitn(unloncitle reads : Shody> “histuneitg/h> Script> { function add(a, by { ( var ¢ /Mocal variable cuasby OQ return (¢ O , var rest \ result» a0, 20; consoleog(result}; //30 O varx=100, var y = 250; HTML, CSS, JavaScript, Bootstrap Page 3291422 Harsha Vardhan (UI Expert) at Durgasoft Udemy courses at 650 INR -htps://www.udemy.com/courses/search/?4 ‘var result2 = add(x,y); consolelag(cesult2);//256 -fhtmt> Arguments - Example -ltle>Arguments 2 -chl>Arguments 2 script> ‘ function funt(a,b) q t console log(arguments); ) fun3(20, 20), fun4(20, 20, 30); [Recursion : ] + Recursionis a technique of calling a funetion inside itself + Whenever afunctionitalls itself, itis said to bettecurston”. ide tile function and call the same function, only if the condition xamgle: FA@oriai of nlimbéf=n * Wiign-2*n-3...°0 % Factorial of 5="5"4*3-2* suntan 47 i function functionnamel) { i samefunctionniame(); Recursion -<>Recursione/h1> -fitmt> eerie rae cans introduction to Objects * Object Oriented Programming (OOP) is a programming paradigm ‘programming style), which is based on the concept of “objects”. Object representsa physi tem [entity Object sa collection of twetypes of members: 1, Properties, Fields 2. Methods | - + Properties / Fieldsietaiiabout the Object. Properties are the variables stored inside the abject Properti¢gare used tOstore datlabout spific person, product or thing, Methods: Mahipulationsiouthe propeities. Methods are the functions stored inside the object. Fuiletions read Values from properties and/or write values into properties. O ¥ 4 ~ 7 “Car BH », > fu) ~ Propetties * carM@ilel: Honda City O = carColoF|Biack * colorNo: 1234 c ~ Methods a start() + changeGearl) * stopl) ‘+ Im the above example, the "Car" object has three properties called "carModel", "carColor", t “colorNo", which have respective values. The HTML, CSS, Javascript, Bootstrap Page 333102 Harsha Vardhan (UI Expert) at Durgasoft Udemy courses at 650 INR - htps://www.udemy.com/courses/search/?q-harsha [Types of Object Oriented Programming (OOP) languages, ‘+ Weave two types of OOP languages: 1. Class-based Object Oriented Programming Language 2. Prototype-based Object Oriented Programming Language [[ereating Objects * Wecan create objectin 2 ways: 1. Object Literals 2. Constructor Function ‘+ Object literals are represented as curly braces {}, which ean include properties ald methods. + The property and value are separated with :8jmbol + Syntax: {“property”: value, “method”: furetion( ) fal FP { Object fiterals -ethtm> methods to the object. The "this" keyword inside the constitictor function reptsents the cufrent working object. For ‘example, ifitis called for thé firsttime, the Mthis® keuord represents the first object; i itis called second time, the "this" Keywvord représents the second object. The constructor function canireceive ohe or more parameters and initializes the same values into the respective pfperties. The "reference varlabletstores the reference (addtéss) ofthe object and used toaccess its members (properties and methiods), olitside the object Iteral / constructor function. funétion functfonnme(arguments) t B® » this.property = value; ttis.method =functiont )(. } var variablename = new functionname( }; Constructor Function -Constructor Function HTML, C55, JavaScript, Bootstrap Page sala Harsha Vardhan (UI Expert} at Durgasoft Udemy courses at 650 INR - htpsi//www.uremy.com/courses/search/2a=harsha ~script function Student(a,b.¢) ( thisstudentid = a thisstudentname = b; thissmanks = ¢; this.result = function ( if (Qhismarks >= 35) { return "Pass else ( return Fai’ , k ) var stu = new Student(2, "Scott, 80) console.og(stu; consotelog(su.studentid); console.log(stustudentnare consoleog(stumark); consoledog(sturesult)
[Object.Keys £ S * The “Otject keys" aed ‘silsed to retilave the listof properties of an object as an array. + Sometimes}jau will geiata from yer /BRBuser storage. Then youdon'*know what properties / fethods are pfsent insidaithe object Thien you have to use Object-keys() are used to properties / methods ofthe objet und algo read its values programmatically symtaxityy objet keysiBerence variable); Example: Object.kelsistu); ‘+ Thisis useful if Yau don't know what properties are existin the object Example on ObjectKeys_ hs -alitle>Keys Keys
scripts function Studentta, b, ¢) { HTML, CSS, JavaScript, Bootstrap Page 3361422 Cor a OU VU Harsha Vardhan (UI Expert) at Durgasoft Udemy courses at 650 INR - htps://www.tidemy.com/courses/search/?q=harsha if thismarks >= 35) { return "Pass'; else { return Fat’ ) * ) var stu = new Student(1, "Scott’, 80); consolatog(stu); var keys = Objectkeys(stu) consolelog( keys for vari 0; < Keystength; e+) { consoletog(stulkeysill: Asiaby [Json + "JSON" stands for MdavaReript Objectiotation". + JSON ig Sipjtarto “Object Litefatlsbut hating the following differences. + In OBjec: Literal lofble quite are optional forthe properties; In" JSON", double quotes are mustfor properties. = ln "Object Liteyat, metipods are allowed; In“JSON", methods are not allowed. + JSON is mainly used as dita exchange format; it can be transferred from browser to server, and vice versa; and alsQit is can be st@red in the local storage and session storage. Syntax: { "property": valle) "property" : value, ( Stringity am) ‘+ The "JSON.stringify" is used to convert “Object Literal” to “JSON” format. JSON is a text format which follows "JavaScript Object Literal” syntax. JSON is mainly used for store or exchange data between browser and server ‘Syntax: JSON.strngify(reference variable) Example: —JSONstringiy(stu) HTML, CSS, JavaScript, Bootstrap Page 397/422

You might also like