1 00:00:00,470 --> 00:00:04,710 So this is the introduction of object oriented programming in JavaScript. 2 00:00:04,730 --> 00:00:06,470 It was known as OOP. 3 00:00:06,470 --> 00:00:13,400 OOP stands for Object Oriented Programming and it was introduced in ES6 version of JavaScript. 4 00:00:13,430 --> 00:00:17,960 Object oriented programming is a coding methodology or a style or a pattern. 5 00:00:18,110 --> 00:00:22,670 It is introduced to convert our big line of code into a smaller line of code. 6 00:00:22,880 --> 00:00:30,350 With this, we can make our code more modular and reusable that we can use that code over and over again. 7 00:00:30,560 --> 00:00:36,560 It makes our code well organized, and let's make our code very easier to debug. 8 00:00:36,590 --> 00:00:37,120 Debug. 9 00:00:37,280 --> 00:00:43,640 I mean, if there is an error in our code and the method, the catching the error is called debug. 10 00:00:43,640 --> 00:00:47,950 Basically, we do not use object oriented programming for small task. 11 00:00:47,960 --> 00:00:50,880 It is used for big and complex projects. 12 00:00:50,900 --> 00:00:57,410 It is currently used in various JavaScript framework like React.js, AngularJS, Vue.js and these are 13 00:00:57,410 --> 00:00:59,360 all based on modern JavaScript. 14 00:00:59,390 --> 00:01:05,390 If you want to understand object oriented programming, first you need to understand two terms. 15 00:01:05,570 --> 00:01:08,980 First one is class and second one is object. 16 00:01:08,990 --> 00:01:15,620 If you understand these two concepts, then you understand 50% of object oriented programming and the 17 00:01:15,620 --> 00:01:18,890 OOP concept used in every high level programming language. 18 00:01:18,920 --> 00:01:23,420 So at first let's try to understand what is class and objects. 19 00:01:23,720 --> 00:01:26,900 Let's try to explain it with graphical images. 20 00:01:27,050 --> 00:01:33,710 Suppose we have a blueprint of a building and a builder build houses with this blueprint. 21 00:01:33,830 --> 00:01:38,270 So according to the blueprint, every building the builder make is similar. 22 00:01:38,360 --> 00:01:41,060 All building designs are identical. 23 00:01:41,060 --> 00:01:47,930 As you can see, the blueprint has three bedrooms and one kitchen, so every building is pretty similar. 24 00:01:47,930 --> 00:01:51,440 So we can accept our blueprint as a class. 25 00:01:51,620 --> 00:01:55,820 And all the buildings made by this blueprint are objects. 26 00:01:55,940 --> 00:02:00,080 The point is, objects are made with this class. 27 00:02:00,260 --> 00:02:04,610 Let me show you another example and it little advance. 28 00:02:04,730 --> 00:02:09,860 Suppose we have a class named car and these are two actual cars. 29 00:02:09,980 --> 00:02:13,910 First one is Maruti Swift and second one is Toyota Fortuner. 30 00:02:14,180 --> 00:02:16,340 So we create a class named car. 31 00:02:16,640 --> 00:02:22,580 And our actual cars are objects which is made by the car class. 32 00:02:22,730 --> 00:02:30,860 And as you know, every car have some common properties like their color engine seat, their AC and 33 00:02:30,860 --> 00:02:32,180 their prices. 34 00:02:32,480 --> 00:02:39,620 We call them properties in programming language and these properties are associated with one or more 35 00:02:39,620 --> 00:02:40,460 classes. 36 00:02:40,790 --> 00:02:43,370 Every class have their own property. 37 00:02:43,370 --> 00:02:47,390 As you can see, we have two actual cars, Swift and Fortuner. 38 00:02:47,660 --> 00:02:51,980 Their properties are same, but their value is different. 39 00:02:51,980 --> 00:02:57,260 As you can see Maruti have four color option but Toyota have five color option. 40 00:02:57,260 --> 00:03:04,220 Maruti provide 1200 cc engine and Toyota provide 2700 cc engine. 41 00:03:04,580 --> 00:03:12,020 Maruti provide five seat and Toyota provide seven seat and both the car provide SC and also you can 42 00:03:12,020 --> 00:03:14,870 see there is huge price difference between these two. 43 00:03:14,900 --> 00:03:20,690 Car properties are basically a variable and we can set different value for this variable. 44 00:03:20,690 --> 00:03:26,300 And if you want to change and manipulate the values, then you need to use methods. 45 00:03:26,600 --> 00:03:30,050 Our classes are made with properties and methods. 46 00:03:30,320 --> 00:03:33,380 Suppose I create a class named calculation. 47 00:03:33,380 --> 00:03:36,440 Then I create some variable as properties. 48 00:03:36,680 --> 00:03:42,830 We declare these three variable within this class, and if you want to assign values to these properties, 49 00:03:42,830 --> 00:03:44,570 you need methods. 50 00:03:44,780 --> 00:03:47,380 Methods are basically functions. 51 00:03:47,390 --> 00:03:49,970 Suppose we want to add numbers. 52 00:03:49,970 --> 00:03:52,490 So I'm going to create a function named sum. 53 00:03:52,730 --> 00:03:56,300 And as you can see we perform some calculation in this function. 54 00:03:56,300 --> 00:04:04,370 First we take a variable name c and then add two variables a and b and we return c. 55 00:04:04,670 --> 00:04:11,750 We can use only those property in our method, which we already declared in our class, and we cannot 56 00:04:11,750 --> 00:04:15,560 use properties which is defined in outside the classes. 57 00:04:15,560 --> 00:04:21,860 Here you can see we just create one method in our class, but you can create multiple methods in this 58 00:04:21,860 --> 00:04:23,720 class at the same way. 59 00:04:23,720 --> 00:04:28,610 I'm going to create another method name sub sub mean subtraction. 60 00:04:28,610 --> 00:04:32,360 So let me show you the syntax how we can declare class. 61 00:04:32,540 --> 00:04:36,380 And also I'm going to show you how we can create property and methods. 62 00:04:36,500 --> 00:04:39,200 Suppose I'm going to create a class name. 63 00:04:39,200 --> 00:04:39,590 Hello. 64 00:04:39,740 --> 00:04:41,960 So at first we need to type class keyword. 65 00:04:41,960 --> 00:04:44,210 Then our class name which is hello. 66 00:04:44,240 --> 00:04:46,130 Then inside the curly braces. 67 00:04:46,250 --> 00:04:49,490 Here we need to create properties and method inside this class. 68 00:04:49,490 --> 00:04:53,450 Suppose I want to create a method named methods for that. 69 00:04:53,450 --> 00:04:57,320 First we need to take the method name in our case masses. 70 00:04:57,320 --> 00:04:59,930 It's a normal function just here we don't need. 71 00:05:00,060 --> 00:05:02,880 To use function keyword before the function name. 72 00:05:03,000 --> 00:05:06,630 At the same way, for parameters, we need to use parenthesis. 73 00:05:06,660 --> 00:05:10,380 Then inside the curly braces we can define our masses. 74 00:05:10,410 --> 00:05:12,270 In our case I want to print. 75 00:05:12,300 --> 00:05:14,220 Hello everyone in our console. 76 00:05:14,490 --> 00:05:16,950 Now masses become a method. 77 00:05:17,070 --> 00:05:23,040 You can create multiple methods in a class and if you want to call this method first you need to create 78 00:05:23,040 --> 00:05:25,260 an object using this class. 79 00:05:25,380 --> 00:05:30,600 So first we need to take a variable in our case A and assign this class. 80 00:05:30,930 --> 00:05:34,200 Also to assign this class we need to use new keyword. 81 00:05:34,230 --> 00:05:35,700 Then our class name. 82 00:05:35,850 --> 00:05:39,240 This will turn our variable into an object. 83 00:05:39,270 --> 00:05:44,280 After creating this object, we can access all the properties and methods from this class. 84 00:05:44,340 --> 00:05:47,280 Suppose I want to call masses method. 85 00:05:47,310 --> 00:05:52,170 Then first we need to type the object name in our case a dot. 86 00:05:52,200 --> 00:05:54,420 Our method name message. 87 00:05:54,540 --> 00:05:58,080 And if you want to send any argument then you can do. 88 00:05:58,110 --> 00:06:00,350 Usually we need to do it for function. 89 00:06:00,690 --> 00:06:02,520 So this is it for this tutorial. 90 00:06:02,520 --> 00:06:05,540 In the next tutorial we are going to learn about practical. 91 00:06:05,550 --> 00:06:07,200 So thanks for watching this video. 92 00:06:07,200 --> 00:06:09,300 Stay tuned for the next tutorial.