JavaScript Treehouse Club - MASH MASH - JavaScript Handle Submission and Event Handler Functions

Kegan Windle
Kegan Windle
2,217 Points

What is the difference between a parameter and a class?

I feel like I should have gotten this earlier.

2 Answers

Gyorgy Andorka
Gyorgy Andorka
13,808 Points

A class is kinda like a "blueprint" of an object, which is data stored in variables ("state") and functions/methods ("behaviour") encapsulated in a "box".

A function is an block of executable code (doing some specific task) packaged together, making it reusable. A "method" is a function which belongs to a class.

When you define a function, you can declare parameters inside the braces after the function name, which are variables reachable/usable inside your function. When you actually call the function, you give it "arguments", i.e. actual values to be assigned to those parameter variables.

function add(a, b) {  // a, b are parameter variables
  return a + b; 
} 

// using the above defined function
console.log(add(1, 2))  // 1, 2 are argument values

A parameter is the argument that is passed into a function, while a class is a stand-alone object with behaviors and attributes..

For example: class Great { methods here }
While parameters are the arguments that a function takes.

Function example: function methodname(parameter name){ }