Shreya Profile picture
20 Sep, 36 tweets, 11 min read
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

Shreya 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

16 Sep
70+ Awesome Free Resources To Learn JavaScript ๐Ÿ‘‡
(links in the last tweet ๐Ÿ”ป)

๐Ÿงต mega thread

#100DaysOfCode
Documentations ๐Ÿ“‘

1. MDN Web Docs
2. JavaScript Info
3. W3 Schools
4. DevDocs
5. JavaScript Garden
Web Tutorials ๐Ÿ“

6. Learn JS
7. JavaScript Tutorial

---

GitHub Repositories ๐Ÿฑ

8. 30 seconds of code
9. Airbnb JavaScript Style Guide
10. JS Questions
11. 33 JS concepts
12. JS by example
13. Modern JavaScript tutorials
Read 14 tweets
16 Sep
16 free alternatives to Font Awesome

โ†’ Icons for your web development projects ๐Ÿ‘‡

#webdevelopment
- Unicons (best so far)
- Flaticon
- IconFinder
- TheNounProject
- Material Design Iconic Font
- Octicons
- Android Icons
- NucleoApp
- Line-Awesome
- DevIcons
- LineIcons
- FeatherIcons
- StreamLineIcons
- LinearIcons
- MaterialDesignIcons
- Open Iconic

links below ๐Ÿ”ป
Read 4 tweets
15 Sep
12 Websites to take Design Inspirations for your next web development project ๐Ÿ‘‡

#webdevelopment
1. OnePageLove

onepagelove.com
2. CSS nectar

cssnectar.com
Read 13 tweets
16 Aug
14 best YouTube channels to learn web development for free ๐Ÿ‘‡

a thread ๐Ÿงต
#webdevelopment #CodeNewbie
Read 16 tweets
5 Aug
15 websites to start freelancing as a software developer ๐Ÿ‘‡

#webdevelopment start freelancing as a soft...
1. Upwork
upwork.com

2. Freelancer
freelancer.com

3. PeoplePerHour
peopleperhour.com

4. Toptal
toptal.com

5. Fiverr
fiverr.com/s2/ef47ef018f
6. Truelancer
truelancer.com

7. StoreTasker
storetasker.com

8. Crossover
crossover.com

9. Turing
turing.com

10. arc .dev
arc.dev
Read 4 tweets
30 Jul
10 FREE @udemy courses to become a full stack web developer (in an arranged order):
What's included? ๐Ÿ‘‡
โœ… HTML & CSS
โœ… 2 Projects (HTML + CSS)
โœ… JavaScript
โœ… Web design
โœ… Project (HTML + CSS + JS)
โœ… Git & GitHub
โœ…Noje JS
โœ… Express JS

โคต
#100DaysOfCode #webdevelopment #JS
1. Learn HTML & CSS From Scratch! The Beginners Guide

โ†’ Ever wanted to make websites but didn't know how to start? Then this course was made for you!

udemy.com/course/learn-hโ€ฆ
2. Learn HTML5 and CSS3 By Coding Your First Website

โ†’ Learn and build your own website with HTML5 and CSS3

udemy.com/course/learn-hโ€ฆ
Read 12 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

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

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!

:(