Sumit | Javascript + React
Sumit | Javascript + React

@sumitsaurabh927

9 Tweets 1 reads Apr 05, 2023
Javascript fundamentals for web development: Classes in Javascript
โœ… Classes are used extensively in React and
are an integral part of object-oriented programming.
A thread ๐Ÿงต
๐Ÿ‘‰ We jumped from procedural programming to object-oriented programming because things had started to become pointlessly lengthy:
๐Ÿคฎ A variable in line no.8 being accessed by a function on line no. 122 and the returned value of that function is used on line no. 55.
๐Ÿฅฒ This meant that coders had to scroll up & down a lot & keep track of a lot of stuff, which became useless in object-oriented programming because data and functions were clubbed together in entities called Objects.
But soon enough this approach became lengthy as well..๐Ÿ‘‡
๐Ÿงฟ When we needed to make a lot of objects of very similar kind (like users in a social media site), we had to use contructors & factory functions using the 'new' keyword.
โœŒ๏ธ But in modern Javascript, we've an even more powerful concept of classes.
Let's look at them now....๐Ÿ‘‡
๐Ÿš€ In object-oriented programming, a class is an extensible program-code-template for creating objects, providing initial values for state ( variables) & implementations of behavior ( functions or methods).
Let's break this ginormous sentence into easy-to-digest chunks..๐Ÿ‘‡
1๏ธโƒฃ ' a class is extensible ' -> meaning we can add features to the entity that a class will create
2๏ธโƒฃ 'program-code-template for creating objects,' -> meaning it is template for creating objects, i.e., the entity that a class creates is object.
3๏ธโƒฃ 'providing initial values for state ( variables)' -> meaning that objects created using a class can or can not have variables that define the initial state of the class.
And finally....๐Ÿ‘‡
4๏ธโƒฃ '& implementations of behavior ( functions or methods)' -> meaning that the output-ed object can also have or not have functions that implement the behaviour.
๐Ÿ’ก Function of an object are called methods and if an object only has functions, it is said to have a behaviour.
I write threads daily on web dev so if you enjoyed this thread, please:
โœ… Follow me @sumitsaurabh927 for more of these.
โค๏ธ Each like, every comment of y'all motivates me to come up with awesome new stuff!
โœ… RT the tweet below to show me some love.

Loading suggestions...