<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Oyedokun Ipinoluwa</title>
    <description>The latest articles on DEV Community by Oyedokun Ipinoluwa (@oluwalomo).</description>
    <link>https://dev.to/oluwalomo</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2745366%2Fe6cd1637-c04c-428f-a9d6-ba57b926ce53.png</url>
      <title>DEV Community: Oyedokun Ipinoluwa</title>
      <link>https://dev.to/oluwalomo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/oluwalomo"/>
    <language>en</language>
    <item>
      <title>Classes in javascript</title>
      <dc:creator>Oyedokun Ipinoluwa</dc:creator>
      <pubDate>Wed, 22 Jan 2025 04:44:37 +0000</pubDate>
      <link>https://dev.to/oluwalomo/classes-in-javascript-2n39</link>
      <guid>https://dev.to/oluwalomo/classes-in-javascript-2n39</guid>
      <description>&lt;p&gt;Classes&lt;br&gt;
 **&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Classes are blueprints for &lt;/li&gt;
&lt;li&gt; Classes provide a more formal and organized way of defining objects and their behaviour.&lt;/li&gt;
&lt;li&gt;A JavaScript class is not an object rather it's a template for JavaScript object.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  -  A class is a type of function, but instead of using the word "function " to initiate it, we use the keyword "class", and the properties are assigned inside a constructor()method.
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;              Class Method&lt;/li&gt;
&lt;li&gt;  1. Class Method are created with the same syntax as object methods.&lt;/li&gt;
&lt;li&gt; 2. Use the keyword class to create class.&lt;/li&gt;
&lt;li&gt;  3. Always add a constructor()method.&lt;/li&gt;
&lt;li&gt;  4. Then add any no of method.&lt;/li&gt;
&lt;li&gt;  Example 1: Create a car class, and then create an object called "my car" based on the car class.&lt;/li&gt;
&lt;li&gt;   Class car {&lt;/li&gt;
&lt;li&gt;Constructor (brand) {&lt;/li&gt;
&lt;li&gt;this.car name=brand;&lt;/li&gt;
&lt;li&gt;}&lt;/li&gt;
&lt;li&gt;}&lt;/li&gt;
&lt;li&gt;My car=new car****

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Constructor method&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Constructor method is a special method used for initializing object created with a class. It's called automatically when a new instance of the class is created. It typically assigns initial values to object properties using parameters passed to it. This ensure objects are properly initialized upon creation.&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;When a constructor is called automatically and  a class is initiated, it has to have the exact name "constructor", in fact, if you do not have a constructor, JavaScript will add an invisible and empty constructor method.&lt;br&gt;
-Note: A class cannot have more than one constructor() method.this will throw a syntax error.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;More examples on classes.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Class person&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Class student{&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Constructor(rollno, name, age){&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;this.name=name;&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;this.roll No=roll No;&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;this.age=age;&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;}&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;}&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Let student 1=new student(1,"Alex",12);&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Console.log(student 1); student [name: 'Alex', roll No:1, age:12&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Class product{&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Constructor(name, price){&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;this.name= name;&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;this.price= price;&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;}&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;display product(){&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Console.log('product:${&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;this.name}');&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Console.log('price:${&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;this.price}');&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;}&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;}&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Const product 1=("shirt,19.32);&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Const product 2=("pant", 33.55);&lt;br&gt;&lt;br&gt;
**&lt;/p&gt;&lt;/li&gt;

&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
