Functions

2 minutes
Share the link to this page
Copied
  Completed
The var statement declares a variable, optionally initialising it to a value.

Transcript

Hello, in this JavaScript video, I am going to show you functions. So we've already technically done one and it's the constructor. So this is the basic function that is called by default, when you create a new object of that particular class. So to create any other function, unlike inside a class if you don't use the keyword function, and you just won't put the name of your function, so I'm gonna say, epic font, open curly bracket, curly braces. And that's it. So if we put some code in here, let's see if we do a console dot log.

Big ocean and to actually use the function you can just do this and call OBJ dot that pick fun It doesn't matter okay for reload says this is an epic function and obviously Will on the car OBJ two obviously at the moment, it doesn't actually do anything different. Or like any other variable, I mean any other method, you can actually pass in parameters as well. So if you don't have to do that, feel free to take a look at the regular functions video. Once you know Frou Frou Feel free to come back and experiment as an extra task, what I want you to do is do two functions to malfunction, one that, let's say takes in two values, multiply them together under the console, log or even turn the value that's totally up to you. The other thing we're going to do is have a function that merely you know utilizes these values in some way.

So to access the x and y variables from this class within the class mean just make sure you put this dot x and this dot y anywhere that you need them, maybe add them together, maybe print them out in a slightly different format. But that is it for functions and classes. If you have any questions, feel free to drop me a message and I look forward to seeing you in the next video.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.