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 - 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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
Introduction to classes1m 53s
-
(Locked)
Defining a class8m 32s
-
(Locked)
Differences between functions and classes1m 42s
-
(Locked)
Hoisting explained with classes2m 27s
-
(Locked)
Strict mode with classes explained1m 25s
-
(Locked)
What are static methods and usage?4m 11s
-
(Locked)
Prototype methods explained and usage2m 25s
-
-
-
-