Shreya Purohit | Data Analyst Profile picture
Sep 20, 2021 โ€ข 36 tweets โ€ข 11 min read โ€ข Read on X
One of the required prerequisites to learn React is ๐—˜๐—ฆ๐Ÿฒ.

๐‘‚๐‘›๐‘’ ๐‘ โ„Ž๐‘œ๐‘ข๐‘™๐‘‘ ๐‘˜๐‘›๐‘œ๐‘ค ๐ธ๐‘†6 ๐‘คโ„Ž๐‘’๐‘กโ„Ž๐‘’๐‘Ÿ ๐‘ฆ๐‘œ๐‘ข'๐‘Ÿ๐‘’ ๐‘™๐‘’๐‘Ž๐‘Ÿ๐‘›๐‘–๐‘›๐‘” ๐‘…๐‘’๐‘Ž๐‘๐‘ก ๐‘œ๐‘Ÿ ๐‘›๐‘œ๐‘ก.

๐Ÿงต This thread is all you need to know about ES6 before you get your hands on React:

#100DaysOfCode #javascript
โš›๏ธ You'll be able to learn React way better if you know working with ES6.

ES6 is a scripting language for JavaScript and helps developers by making the code simple as it handles out all the limitations of the main language (JS).
๐Ÿ‘‡
๐Ÿญ. ๐—ฆ๐—ฐ๐—ผ๐—ฝ๐—ฒ ๐—ผ๐—ณ ๐—ฉ๐—ฎ๐—ฟ๐—ถ๐—ฎ๐—ฏ๐—น๐—ฒ๐˜€ ๐—ถ๐—ป ๐—๐—ฆ
Before moving to the point, let us understand 3 concepts here:

1๏ธโƒฃ Global Scope - Variable is declared outside the function. This variable is accessible inside every function present in the code.
2๏ธโƒฃ Function Scope - Variable is declared inside (within) a function, outside that it is not accessible anywhere.

3๏ธโƒฃ Block Scope - Block scope means variables that are declared in a { } block are not accessible outside it. This block can be an if statement, for/while loop..
๐Ÿฎ. ๐—น๐—ฒ๐˜/๐—ฐ๐—ผ๐—ป๐˜€๐˜ ๐—ผ๐—ฟ ๐˜ƒ๐—ฎ๐—ฟ?

- var: function/ global scoped
var is both global and function scoped, which often creates a confusion. So avoid using it.
- let: block scoped.
โ†’ let keyword can be reassigned:

But when we use let inside a function, it works like:

Inside the function box() when we log the value of size, it shows a reference error. That is because let is block scoped.
- const: block scoped

โ†’ const is very similar to let except that they can't be changed and redeclared.

โ†’ therefore let and const are preferred over var keyword for declaring variables.
๐Ÿฏ. ๐—ข๐—ฏ๐—ท๐—ฒ๐—ฐ๐˜๐˜€

-> objects are written within curly braces { } as a collection of key: value pairs.

key: property name
value: value of that property

- Creating an empty object:
Talking specifically about ES6, before ES6 we had to specify both (key, value) even if both are of the same names.

ES6 helps us to get rid of duplication when we have the same key: value names. So now our code will look like this:
๐Ÿฐ. `๐˜๐—ต๐—ถ๐˜€` ๐—ธ๐—ฒ๐˜†๐˜„๐—ผ๐—ฟ๐—ฑ

this is a keyword. It basically returns a reference to the object it is placed within

๐Ÿ’ก NOTE:
When we call a function as a method in an object, this keyword returns a reference to that object. ๐Ÿ‘‡
But when we call the function alone, outside the object this returns the global object (browser window) and hence we get the result as undefined ๐Ÿ‘‡
๐Ÿฑ. ๐—”๐—ฟ๐—ฟ๐—ผ๐˜„ ๐—™๐˜‚๐—ป๐—ฐ๐˜๐—ถ๐—ผ๐—ป๐˜€

- Helps us to write functions in a much shorter, concise, and easier way.

- Having a single argument can remove the () around our parameters (num in below case)
๐Ÿฒ. ๐—ข๐—ฏ๐—ท๐—ฒ๐—ฐ๐˜ ๐——๐—ฒ๐˜€๐˜๐—ฟ๐˜‚๐—ฐ๐˜๐˜‚๐—ฟ๐—ถ๐—ป๐—ด

Let's say we have an object called girl such that it has 3 keys such as:

const girl = {
name: " ",
age: " ",
country: " ",
};

Normally, we would do something like this to get the values:
here, as you can see we have to repeat the object name girl every time we want to get a value. This problem can be solved by object destructuring:

๐‘๐‘œ๐‘›๐‘ ๐‘ก { ๐‘›๐‘Ž๐‘š๐‘’, ๐‘Ž๐‘”๐‘’, ๐‘๐‘œ๐‘ข๐‘›๐‘ก๐‘Ÿ๐‘ฆ } = ๐‘”๐‘–๐‘Ÿ๐‘™;

this one-line code works the same as the previous code.
So destructuring made our code shorter and easier to understand.

In case you want to use an alias (a different variable name) instead of key:

๐‘๐‘œ๐‘›๐‘ ๐‘ก {๐‘๐‘œ๐‘ข๐‘›๐‘ก๐‘Ÿ๐‘ฆ: ๐‘๐‘ก๐‘Ÿ๐‘ฆ} = ๐‘”๐‘–๐‘Ÿ๐‘™;

- This above line of code means we've defined a new variable called ctry = country.
๐Ÿณ. ๐—ฆ๐—ฝ๐—ฟ๐—ฒ๐—ฎ๐—ฑ ๐—ข๐—ฝ๐—ฒ๐—ฟ๐—ฎ๐˜๐—ผ๐—ฟ
- We use spread operator for adding items to an array, combining arrays/ objects, merging or cloning and array, and many more. Let's have a quick look at each of them:

Let's say we have two arrays such that
Case 1 - ๐ด๐‘Ÿ๐‘Ÿ๐‘Ž๐‘ฆ๐‘ 
๐ถ๐ด๐‘†๐ธ ๐ผ๐ผ - ๐‘‚๐‘๐‘—๐‘’๐‘๐‘ก๐‘ 
๐Ÿด. ๐—–๐—น๐—ฎ๐˜€๐˜€๐—ฒ๐˜€

-> they behave as a template for creating objects

Let us take an example of an object boy here. We have a function called run inside it.

Now if we've some bug in the future or we've to modify our function for a different object, it would be a long way.
- To overcome this and make our work easier, we use classes:

*Always add the constructor method when creating objects*
Now that we've created a class, let's try building our object again -

see it's that simple!
with this above class, we've implemented the run method in a single line of code. If someday we find a bug here, we've to modify it in just a single place {inside class Boy}. So this is the advantage of using classes in JS.

Now let's talk about Inheritance..
๐Ÿต. ๐—œ๐—ป๐—ต๐—ฒ๐—ฟ๐—ถ๐˜๐—ฎ๐—ป๐—ฐ๐—ฒ

-> when we acquire properties of one class into another class to extend it, it is inheritance.

If we have a class Boy such that -
..and we want to create another class (having similar properties + some specific properties of its own). We can do this using the keyword ๐‘’๐‘ฅ๐‘ก๐‘’๐‘›๐‘‘๐‘ 
we just created the class Girl here. Let us now create a const using this -

๐‘๐‘œ๐‘›๐‘ ๐‘ก ๐‘š๐‘ฆ๐บ๐‘–๐‘Ÿ๐‘™ = ๐‘›๐‘’๐‘ค ๐บ๐‘–๐‘Ÿ๐‘™("Sara");

and we're done. This code basically means that now the const myGirl will have the functions eat + run + constructor property of Boy class.
Now we can use it like below without writing a long piece of code:

myGirl. eat()
myGirl. run()
Now let's say we want to create another constructor inside the Girl class (derived class constructor).

We must call ๐‘ ๐‘ข๐‘๐‘’๐‘Ÿ() constructor inside the new constructor, otherwise, we'll get an error. Now, this must be looking confusing, let's look at the example below -
๐Ÿญ๐Ÿฌ. ๐— ๐—ผ๐—ฑ๐˜‚๐—น๐—ฒ๐˜€

At times, we can have many no. of classes declared in a single file. This makes the code long, confusing and messy.

To avoid this, we separate these classes into different files and import them as a module into the main file.
This is called modularity.
Let's look at it in action. Here's what our folder ๐‘ ๐‘Ÿ๐‘ will look like:

Here we created two files (boy, girl) inside ๐‘ ๐‘Ÿ๐‘ folder.

Doing this simple setup can make our code much easier to understand!

Why we used ๐‘–๐‘š๐‘๐‘œ๐‘Ÿ๐‘ก and ๐‘’๐‘ฅ๐‘๐‘œ๐‘Ÿ๐‘ก? ๐Ÿ‘‡
both Boy and Girl classes are private in the folder, in order to use them we made them public using the ๐’†๐’™๐’‘๐’๐’“๐’• keyword.

*We use ๐‘–๐‘š๐‘๐‘œ๐‘Ÿ๐‘ก keyword in line 1 of girl.js as it is an extended version of the Boy class.*
Now half of the work is done. For now, these classes are not accessible in our main app.js file. For that, we've to import them into our app.js file. We can do that by using -
๐Ÿญ๐Ÿญ. ๐——๐—ฒ๐—ณ๐—ฎ๐˜‚๐—น๐˜ ๐—ฎ๐—ป๐—ฑ ๐—ก๐—ฎ๐—บ๐—ฒ๐—ฑ ๐—˜๐˜…๐—ฝ๐—ผ๐—ฟ๐˜๐˜€

- Named Exports

We can export more than one object from a specific module. This is called named export. Eg:

Here we exported a class `Car` and a function `add`.๐Ÿ‘‡
- Default Exports

It is basically the main object that is exported from the module. It is generally used in case we've only a single object to export. Let's see how it is -
๐Ÿ’ก Now we don't need the import { Car } from "./car";

Instead, we use import Car from "./car"; in case of default exports.
I know this is too long to be called a thread and can be difficult to read, so I've compiled it in a blog. You can read it here:
dev.to/shreya/es6-hanโ€ฆ
๐Ÿ‘‹ Woosh! You've made it to the end. Hope I've helped you somehow.
If it did, ๐Ÿ” and โค๏ธ the thread and let's connect @eyeshreya :)

โ€ข โ€ข โ€ข

Missing some Tweet in this thread? You can try to force a refresh
ใ€€

Keep Current with Shreya Purohit | Data Analyst

Shreya Purohit | Data Analyst Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @eyeshreya

Feb 7, 2023
Cheatsheets that will save you tons of hours as a data analyst:
Read 9 tweets
Jan 3, 2023
Hey data analytics learners! ๐Ÿ“Š

One of the best ways to master a new skill and develop your portfolio is through project-based learning.

6 free virtual project-based internships based on real world scenarios from companies like Deloitte, KPMG, Accenture and Tata โ†“
๐Ÿง  Why should you consider trying these programs:

- Virtual, self-paced and free
- Based on real life scenarios
- Applied knowledge
- Develop your critical thinking skills
- Learn problem solving approaches

Time to dig in! โคต๏ธ
1. KPMG Data Analytics Internship

What youโ€™ll learn:
โ€ข Data quality and analysis
โ€ข Data visualization
โ€ข Perform data-driven insights
โ€ข Build dashboards

โ†’ theforage.com/virtual-internโ€ฆ
Read 9 tweets
Nov 25, 2022
If you're looking to learn Data Analysis in Python, here are some excellent short & concise playlists to follow:

- NumPy
- Pandas
- Matplotlib
- Seaborn
- Plotly
+ Projects!
0. Python:

Want to brush up your python skills right from the fundamentals? This playlist will do the job -

youtube.com/playlist?list=โ€ฆ
1. NumPy:

This is a 1-hour video covering concepts like arrays, indexing, math, statistics, reshaping, and more.

Read 9 tweets
Nov 1, 2022
For the next 3 weeks, @365datascience is offering FREE unlimited access to all of their data science courses!

Make the most of it while you can.

Here are some of the best courses you can enroll in right now:
๐Ÿšจ Before we start, make sure to sign up for the program and log in, or the links below won't open:

๐Ÿ”—365datascience.com/r/55d37cbf41caโ€ฆ

Let's begin! โ†“
1. SQL

Start with the fundamentals and work your way up to more complex topics.

๐ŸŽ“121 lessons
โŒšTime: 8hrs.

๐Ÿ”—learn.365datascience.com/courses/previeโ€ฆ
Read 8 tweets
Oct 22, 2022
My top 3 preferences to learn SQL for free:
1. MySQL Tutorial for Beginners by @moshhamedani

This 3-hour course helps you understand SQL and write queries in no time!

๐Ÿ”—
2. W3Schools SQL

If I need to revise a concept, this is my go-to resource every time.

๐Ÿ”— w3schools.com/sql/
Read 8 tweets
Sep 24, 2022
Building projects is a great approach to stand out from the crowd and expand your data analytics portfolio. ๐Ÿ“ˆ

๐Ÿš€ 8 free datasets for your next data science and analysis projects.

โ†“
1. Google Dataset Search

๐Ÿ”— datasetsearch.research.google.com
2. Kaggle datasets

๐Ÿ”— kaggle.com/datasets
Read 9 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us!

:(