File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 1+ console . log ( "Objects in JavaScript" ) ;
2+ // Objects in JS can be created using 2 methods:
3+ // i) Using Literals
4+ // ii) Using Constructor
5+
6+ // Using Literals
7+ // Using Literals only one object can be created at a time so this method is sometimes inefficient
8+ let myObj1 = {
9+ // This Object contains some information about a BOOK
10+ name : "General Physics" ,
11+ author : "I.E Irodov" ,
12+ published : 2020 ,
13+ description : "Unavailable" ,
14+ } ;
15+ console . log ( myObj1 ) ;
16+ console . log ( myObj1 . name ) ;
17+
18+ console . log ( "********************************************************" ) ;
19+ // Using Constructors
20+ function objConst ( name , author , published ) {
21+ // This Object contains some information about BOOKS
22+ this . name = name ;
23+ this . author = author ;
24+ this . published = published ;
25+ }
26+ // We just made a constructor for an obejct
27+ // Create a new Object using this constructor
28+ let book1 = new objConst ( "NCERT" , "Unknown" , 2021 ) ;
29+ let book2 = new objConst ( "C for Everyone" , "Yashwant Kanetkar" , 2004 ) ;
30+ console . log ( book1 ) ;
31+ console . log ( book2 ) ;
You can’t perform that action at this time.
0 commit comments