Back to articles
Constructor function and Basic Array methods.

Constructor function and Basic Array methods.

via Dev.toMadhavan G

JavaScript is a powerful and flexible language, and two of its most important concepts are constructor functions and arrays . 🔷 What is a Constructor Function? A constructor function is used to create and initialize multiple objects with the same structure. Instead of writing the same object again and again, you define a template and reuse it. Think of it like a blueprint for creating objects. Example: const student1={ name:"arun", age:22 } const student2={ name:"raghu", age:23 } const student3={ name:"sandy", age:21 } const student4={ name:"vicky", age:22 } console.log(student1.name,student1.age) console.log(student2.name,student2.age) console.log(student3.name,student3.age) console.log(student4.name,student4.age) 🔹It's normal object creation for a student details. 🔹This method is enough for one or two person but if we have more than 10 or 20 person we can't use this method. 🔹To overcom this method we are useing constructor function. example: function Student(name, age) { this.name =

Continue reading on Dev.to

Opens in a new tab

Read Full Article
2 views

Related Articles