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

4 Ways to Communicate Across Browser Tabs in Realtime

1. Local Storage Events You might have already used LocalStorage, which is accessible across Tabs within the same application origin. But do you know that it also supports events? You can use this feature to communicate across Browser Tabs, where other Tabs will receive the event once the storage is updated. For example, let’s say in one Tab, we execute the following JavaScript code. window.localStorage.setItem("loggedIn", "true"); The other Tabs which listen to the event will receive it, as shown below. window.addEventListener('storage', (event) => { if (event.storageArea != localStorage) return; if (event.key === 'loggedIn') { // Do something with event.newValue } }); 2. Broadcast Channel API The Broadcast Channel API allows communication between Tabs, Windows, Frames, Iframes, and  Web Workers . One Tab can create and post to a channel as follows. const channel = new BroadcastChannel('app-data'); channel.postMessage(data); And oth...

Certbot SSL configuration in ubuntu

  Introduction Let’s Encrypt is a Certificate Authority (CA) that provides an easy way to obtain and install free  TLS/SSL certificates , thereby enabling encrypted HTTPS on web servers. It simplifies the process by providing a software client, Certbot, that attempts to automate most (if not all) of the required steps. Currently, the entire process of obtaining and installing a certificate is fully automated on both Apache and Nginx. In this tutorial, you will use Certbot to obtain a free SSL certificate for Apache on Ubuntu 18.04 and set up your certificate to renew automatically. This tutorial will use a separate Apache virtual host file instead of the default configuration file.  We recommend  creating new Apache virtual host files for each domain because it helps to avoid common mistakes and maintains the default files as a fallback configuration. Prerequisites To follow this tutorial, you will need: One Ubuntu 18.04 server set up by following this  initial ...

Working with Node.js streams

  Introduction Streams are one of the major features that most Node.js applications rely on, especially when handling HTTP requests, reading/writing files, and making socket communications. Streams are very predictable since we can always expect data, error, and end events when using streams. This article will teach Node developers how to use streams to efficiently handle large amounts of data. This is a typical real-world challenge faced by Node developers when they have to deal with a large data source, and it may not be feasible to process this data all at once. This article will cover the following topics: Types of streams When to adopt Node.js streams Batching Composing streams in Node.js Transforming data with transform streams Piping streams Error handling Node.js streams Types of streams The following are four main types of streams in Node.js: Readable streams: The readable stream is responsible for reading data from a source file Writable streams: The writable stream is re...