Skip to main content

All The JavaScript You Need To Know Before Learning React

 We all have been in this stage. You have just finished an online course or other self-taught resources and have some grip over JavaScript and now the obvious choice is to learn some JavaScript framework. But approaching your first js framework can get really scary. But I beg you to not stop there, we all once had that doubt that we are not ready yet, it is something every developer goes through.

In this post, I will make your transition to the React framework a lot easier. As I have listed down the most used JavaScript concepts used inside React Js.

Before going into React Js you need to first make sure that you have learned the basics of JavaScript. But even after that, there are chances you might not have gone through concepts that React Js require, so please read this post till the end, even if you find it too easy or boring, at least skim over it.

“If you can’t explain it simply, you don’t understand it well enough.”

— Albert Einstein

Coding is a continuous journey, you learn on the way. You need to make one thing clear, no one in this world is completely ready to do something. You just have to do those things.

I always did something I was a little not ready to do. I think that is how you grow.

Let's get going!

  • Es6 classes
  • Array functions (especially filter and map) you will use them a lot!
  • Arrow functions
  • let and const
  • Imports and Exports
  • Spread and Rest Operator
  • The ‘this’ concept

Before var was used to set new variables but with the ES6 updates let let and const were introduced.

But what is the difference between var and let and const ?

var variables are globally scoped or accessible. This means when they are declared outside a function they are accessible throughout your file or window. This can be dangerous because you can change it without knowing, hence getting a lot of errors.

While on the other hand let and const has blocked scope. This means when they are declared inside a function or any block of code, they can’t be accessed outside it. Thus you can’t easily break your code by manipulating or redeclaring the same variable outside the function.

Var variables can be re-assigned and updated easily, let can be updated but not re-assigned, and const can neither be re-assigned nor updated, it is constant(doesn’t change).

Image for post
Image for post

When I started learning about arrow functions, it was a bit tough to get holdover arrow functions, It took me some time to get used to it.

Arrow functions are short and straight to the point. They are almost the same as regular functions but with less syntax.

Image for post
Image for post

Note: Arrow functions are used a lot in modern frameworks, it is a must to learn.

A class is another type of function which is declared by the class keyword and can be used to create new objects. A class contains properties and methods.

The constructor method is used for initializing objects that are created by the class itself and we use this keyword to refer to the current class. For eg in StudentName class this refers to StudentClass.

Image for post
Image for post

One of the most things used in Classes is Inheritance

We use extends in classes to inherit properties from another class.
In the example below, the class TopStudents inherits the property and method from the StudentName class. The super method is used to call the parent constructor. In our case, it will call the constructor of the TopStudent class.

Image for post
Image for post

You can store functions in one Javascript file and later on export it to use it in another Js file by importing the file or a specific function. It comes very handy to organize your code structure.

How to export a file or some functions?
You can use the default when exporting one main thing from the file.

Image for post
Image for post

How import files

Image for post
Image for post

When I first heard of this operator I was so curious to understand how only three dots can be so powerful, simple yet easy to use. To me, the three dots were like magic, a safe way to copy reference types without any issues.

The spread and rest operator uses three dots (. . .) to initialize it.

The spread operator is used for splitting up the values of an array and adding them to another array. Just as it says spread operator spreads values of one array into another array.
The same can be used for objects also.

Image for post
Image for post

This operator is used to represent an infinite amount of arguments in a function.

Contrary we need to specify how many arguments we will provide to a function but what if we don't know how many arguments we will need. Here come the rest operator, you can specify infinity amount of arguments.

Image for post

Array functions are not new but they are still important to know and practice on. In react, map and filter methods are extensively used when dealing with data.

Filter method
The filter method creates a new array of elements that returned true from the call back function passed and filters out the rest.

Image for post

In the example above it returns the objects with people who are 23 years and above only.

Map method
The map method creates a new array from the results of the callback function. The callback is called on each index on the array. The indexes are the elements in the array. Let’s look at an example.

Image for post

This is one of the scariest and troublesome things you face when learning JavaScript. It is confusing and absurd at first, but learning it will be worth all the effort. You might not get it at the first attempt but no worries, this happens to almost everyone.

The JavaScript this keyword refers to the object it belongs to.

Image for post

here this refers to the object person.

Conclusion

To make your transition to react learn JavaScript first, don’t rush the course or documentation. Take your time be it weeks or months to ensure you understand vanilla JavaScript. I repeat don't rush. Not knowing some concept will make your React journey miserable.

I have listed the concepts you will need to get started with your React journey, but keep in mind this is not everything.


Comments

Popular posts from this blog

How to use Ngx-Charts in Angular ?

Charts helps us to visualize large amount of data in an easy to understand and interactive way. This helps businesses to grow more by taking important decisions from the data. For example, e-commerce can have charts or reports for product sales, with various categories like product type, year, etc. In angular, we have various charting libraries to create charts.  Ngx-charts  is one of them. Check out the list of  best angular chart libraries .  In this article, we will see data visualization with ngx-charts and how to use ngx-charts in angular application ? We will see, How to install ngx-charts in angular ? Create a vertical bar chart Create a pie chart, advanced pie chart and pie chart grid Introduction ngx-charts  is an open-source and declarative charting framework for angular2+. It is maintained by  Swimlane . It is using Angular to render and animate the SVG elements with all of its binding and speed goodness and uses d3 for the excellent math functio...

Understand Angular’s forRoot and forChild

  forRoot   /   forChild   is a pattern for singleton services that most of us know from routing. Routing is actually the main use case for it and as it is not commonly used outside of it, I wouldn’t be surprised if most Angular developers haven’t given it a second thought. However, as the official Angular documentation puts it: “Understanding how  forRoot()  works to make sure a service is a singleton will inform your development at a deeper level.” So let’s go. Providers & Injectors Angular comes with a dependency injection (DI) mechanism. When a component depends on a service, you don’t manually create an instance of the service. You  inject  the service and the dependency injection system takes care of providing an instance. import { Component, OnInit } from '@angular/core'; import { TestService } from 'src/app/services/test.service'; @Component({ selector: 'app-test', templateUrl: './test.component.html', styleUrls: ['./test.compon...

How to solve Puppeteer TimeoutError: Navigation timeout of 30000 ms exceeded

During the automation of multiple tasks on my job and personal projects, i decided to move on  Puppeteer  instead of the old school PhantomJS. One of the most usual problems with pages that contain a lot of content, because of the ads, images etc. is the load time, an exception is thrown (specifically the TimeoutError) after a page takes more than 30000ms (30 seconds) to load totally. To solve this problem, you will have 2 options, either to increase this timeout in the configuration or remove it at all. Personally, i prefer to remove the limit as i know that the pages that i work with will end up loading someday. In this article, i'll explain you briefly 2 ways to bypass this limitation. A. Globally on the tab The option that i prefer, as i browse multiple pages in the same tab, is to remove the timeout limit on the tab that i use to browse. For example, to remove the limit you should add: await page . setDefaultNavigationTimeout ( 0 ) ;  COPY SNIPPET The setDefaultNav...