In this lesson we are going to focus on methods. Methods are an important part of object oriented programming (OOP). OOP is an important part of programming which we'll dive into later.
Methods are similar to functions. To prepare for methods, let's do a quick refresher on functions.
Functions are defined using the
function keyword followed by:
- A pair of parentheses
( )with optional parameters inside.
- A pair of curly braces with the function's code inside
- A semicolon
And when we call the function, we can put inputs (arguments) for the parameters.
For example, the
square function on line 2 takes
x as its parameter and returns that parameter squared.