Object Literal vs Constructor Function in JS | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Object Literal vs Constructor Function in JS

Hi! Guys Can anyone describe me the difference between Object Literal and Constructor Function in Javascript? I am confused at this topic...

26th Aug 2021, 2:58 PM
Niranjan Pun
Niranjan Pun - avatar
3 Answers
+ 3
Object literals basically lets you create only a single object per initialisation and all the members have public scope. On the other hand constructor function lets you create multiple instances with members that could have private scope. One would go for object literals if they kind of have some static data to hold and nothing much needs to change but you should use constructor function which helps in creating instances with different behaviour.
26th Aug 2021, 3:34 PM
Avinesh
Avinesh - avatar
+ 1
object literal: simply an object constructor function: it is the method which when called creates an object
26th Aug 2021, 3:26 PM
Harshit Jawla
Harshit Jawla - avatar
0
Avinesh It makes sense. Thanks
27th Aug 2021, 9:28 AM
Niranjan Pun
Niranjan Pun - avatar