From the course: JavaScript: Classes

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Differences between functions and classes

Differences between functions and classes - JavaScript Tutorial

From the course: JavaScript: Classes

Differences between functions and classes

- [Instructor] If you look at it in the end, classes are functions themselves, but because they inherit how they are constructed because of their prototype background, there are some minor differences in between a straight function and a class that might help you determine when to use one over the other. The first difference, as mentioned before, functions are hoisted to the top of your file even when declared dead last versus classes where there aren't hoisted. Functions, expressions and declarations can be overwritten, whereas classes can be extended, but not overwritten. For example, you can't overwrite the door's property in a car class. These are the major differences between the two. So here are a few best practices and use cases. When you want to create a blueprint to be reused over and over and still need functions, create a class and add methods to it. A good example are React class components where we use them…

Contents