• Variables Functioning Theory by Digital Marketing Agency Mumbai


    What's up guys having just finished our discussion on functions I think we now know enough to start taking a look at our final topic which is going to be on classes and objects. So this is not just going to be our last topic but it's also going to bring together everything that we've learned in the previous four sections. So if there's anything from those sections you're unsure about definitely go back and watch the videos of digital marketing agency mumbai before this section.


    That being said this is going to be a nice way to bring everything together. So some of it will be review and some of that will be covering entirely new concepts. So we'll just divide our discussion on classes and objects into our will for five main parts. So we'll get started first by talking about what a class is what an object is and what the relationship is between the two.


    Theory 1:-


    Then we'll take a look at how to add properties to our class will do this with variables. Then take a look at how to add behaviors to the class. This will be done through the use of functions and methods. Then we'll start exploring the concepts of digital marketing agency mumbai using initializes which are a special type of function that helps us create new instances of classes. I'll explain what these mean.


    This is essentially something that we have to pass into the function every time we call upon it. And it's also something that we're using clearly in the code itself. So what this means is when we call upon multiple and pass the Senate array takes on this value that we pass it in. So now we're saying for Nahm in this array it's will execute this code here. Similar is bypassed in some completely different values like fifty-four six three and then number array takes on these values here and I'm not going to run on this because I'll produce quite a large number and we've already seen how it works.


    Anyway now this is pretty good but we can actually go one step further and make it even Bessa even more flexible. So right now it is totaling everything just fine and is princeling the total. But that's it. It's not like we can actually do anything with that total. So instead what we can have this function to do is return something that can return the total so that we can do whatever we want without Tosha, later on, we can add something to it we can subtract something from it.


    Theory 2:-


    We can multiply it to something else we can print out. So on and so forth. So all we really need to do here is get rid of this print code and we'll just go and say return total. So now all function once it finishes executing we'll do this. Ill do our loop the loop and it will get to this and it will basically say OK we're going to return the style. We're going to split some value out. Once we finish executing in a way digital marketing agency mumbai mentioned in concept.


    So now I'm going to call it my function but I can also store the results because it's returning a value in some kind of a variable. So we can say something like results equals multiplied with these numbers. I'm going to go back to the simple version though. And then at the end, I can print results if by ones. So as you can see I got to run this and now I get once when being printed out even though I'm not actually printing anything in the function it sells.


    That's because this function is executing on this array to two that being the parameter and then is going to return the total value and store end result which with a princeling if we wanted to do the shorthand we could actually just print a call to multiply here. So it could just take this copy and paste it in and eliminate the need for my result variable and it will do exactly the same thing. So now that we've covered return values and promises and the basics of functions that is pretty much all we have from digital marketing agency mumbai to discuss on this topic.


    Theory 3:-


    Like I said it's a bit easier to understand that some folk control flows stuff particularly the loops. It's essentially just a convenient way to store our code just to quickly summarize if we want to define our function. We start with death. We give the function a name. The brackets here with any promises that colon to signify that the function body is beginning. And then we put the function body in here.


    Basically the code we want to execute when the function is called we call upon the function by simply typing its name in the brackets beside the function. We just put the values that we once Palsson as the parameter and prompters all values that we Palsson that can be used throughout the function body itself just like any other variable. But they only take on value when we pass the value in as a parameter.


    We know also how functions return values are basically output something once they reached this return statement. And by the way, this return statement doesn't have to be at the end of the function. We just need to make sure that if the function is going to return something it will always return something in all possible cases. The digital marketing agency mumbai didn't include in these examples. Well, actually we did with them for.


    Theory 4:-


    But we can make these functions as complex as we want by. And again lots of control flow. So we can add in loops as we did here. We can add in stuff like if statements. We can even make calls to other functions within the function body itself. OK. Just know that if you're want to return something from a function when you call upon it a result will be output which we can then use in this case with simply printing out.


    But we could use that value as we would any other variable. Otherwise, that wraps up functions nicely and we can move on to our next topic which is going to be classes. So play around with functions Elisabet try to simulate some scenarios in which you think you might need functions a good place to start would be some kind of a simple videogame so implement stuff like play a movements what to do if the player collides with something or just some simple game mechanics that's always a fun and practical example of digital marketing agency mumbai to go on. So once you familiar with functions let's move on to clauses.