10 Things to Know About ES6 before Learning React JS

When you start learning React JS, you’ll probably feel lost if you’re not familiar with the ES6 syntax, even if you have previous experience with Javascript.

If you don’t know much about ES6, ES6 is a standard implemented by Javascript, and it describes all the rules, details, and guidelines that a Javascript implementation should have. And I’ll tell you a secret, there are many different Javascript implementations out there, and that’s why some ES6 features are not available in some browsers (I’m looking at you, IE).

React JS fully embraces ES6, so once you learn and understand the ES6 syntax, your life as a React developer will change because it will be a lot easier to read and write React code.

In this tutorial I will show you some of the ES6 features I think are important to know before you start learning React. But if you prefer to learn from videos like me, check out this video on YouTube:

Are you still here? If so, let’s get started!

Instead of memorizing fancy concepts it’s always easier to understand them by checking examples. Also if possible, I would recommend trying the examples yourself.

const, let, and var

Before ES6, we only had one way to declare variables in Javascript: the “var” keyword. But now we also have “const” and “let”.

const

Variables defined with “const” can’t be redeclared or reassigned.

If you try to reassign a variable defined with “const”, you will get a syntax error:

But if the variable is an object or array, then you can actually change the values of the properties/elements they hold:

Similarly with arrays:

But you can’t reassign the whole object or array:

Variables declared with “const” are block scoped, that means they can only be accessed within the block they were declared. The scope of a variable means where you can access the variable within your code. Let’s see an example:

If you try to access the variable from the function, you will get and undefined error, but outside the function, it will work.

let

A variable declared with “let” can be reassigned:

But can’t be redeclared:

Similarly to “const”, variables declared with “let” are block scoped, that means they can only be accessed within the block they were declared. For example, if you use a “let” variable in a for loop, you can’t access that variable outside the for loop :

var

The “var” keyword is what we all have been using for many years in Javascript, but one of the main issues of declaring variables with “var”, is the scope. If you declare any variable outside a function with “var”, it will be globally scoped. This means you can access that variable from other functions and blocks. This makes your code prone to bugs and hard to debug code. Especially if you run multiple scripts on one page. For example:

You can also redeclare “var” defined variables:

Also reassign them:

When to use what?

You may find many different opinions between developers on how to implement these keywords to define variables. But this is what I would suggest:

  • “const” should be your first option when you define a variable now in Javascript unless you know the value will change.
  • You should only use “let” if you know the value of the variable will change later in your code.
  • “var” should not be an option anymore, and you’ll rarely see the use of “var” in React.

Arrow functions

Arrow functions are a big part of React JS; you will use them everywhere.

This is how you usually create a function before ES6:

And this is how the same function would look like as an Arrow function:

You can notice there’s no “function” keyword. Also you have this arrow (=>) next to the parameters.

But if we only have one line of code in the function, like in this case, we could remove the “return” keyword because there’s an implicit return and also the curly braces. It will look a lot cleaner now:

Also with Arrow functions, we could define default values for our parameters:

Destructuring assignment Arrays and Objects

Destructuring assignment allows you to extract individual items from arrays or objects and assign them to variables using a shorthand syntax.

Destructuring Arrays

Let’s see an example with Arrays. We usually do this to extract values from an array and assign them to variables:

But using ES6 destructuring it becomes a lot simpler:

If you come from PHP, this is very similar to what the list() function does.

Destructuring Objects

Now let’s see and example with objects. Instead of using brackets [] like in the arrays, we enclose the variables with curly braces {} and the properties of the object are assigned to variables of the same name:

But we could also change the name of the variables:

Spread Operator

The spread operator allows you to copy arrays and objects in a shorthand syntax.

Spread Operator for Arrays

Let’s see it in action with arrays:

In that example, we copy the values from numbers1 into numbers2. By adding “…” as prefix to the array, you spread it out.

We could also add more items to the array:

The Spread Operator also can be useful when you have a variable that is an array, and you want to pass it to a function that takes an unknown number of arguments:

In the first example, you won’t be able to call the function just passing the numbers variable as an argument. You need to pass them individually or to add the “…” as prefix to the array to spread the values out.

And here is another cool trick, you could also apply the Spread Operator to a string to convert it to an array:

Spread Operator for Objects

Now let’s see some examples with objects:

In that example, similarly to arrays, we can copy an object by adding the “…” prefix and assigning it to another variable.

The spread operator is also very useful to merge objects. This is a very common if you use something like redux to manage your state in React:

Rest Parameters

In some cases you need to create functions that accept an unknown number of parameters. Before ES6, you could do this using the “arguments” keyword. Let’s see an example:

In that example, we have a sum() function that takes two parameters, but what if we wanted to pass more than two arguments (parameters) to the function?:

We would get the same result, and Javascript will ignore the other arguments.

Javascript provides the “arguments” object to access all the arguments passed to the function. If we console.log “arguments” we could see it’s an object:

The problem with “arguments” is that we can’t apply array functions to it because it’s an object, so we would need to implement other methods to do our calculations. That’s why ES6 introduced Rest Parameters, if we add “…” as a prefix to the parameter in the function definition, then it becomes an array of arguments when the function is called. Then we could apply any array function to it or just have the ability to loop it:

The syntax for Rest Parameters is similar to the Spread Operator, it uses the “…” but you could differentiate them by checking where they are used. If you see “…” in the parameters of the function definition, then you are seeing Rest Parameters. Otherwise it is a Spread Operator.

Template Literals

At some point, we all have to concatenate (join) variables with strings in Javascript, for example, showing a personalized message to the user or customizing a button label. And we know this is a pain to do in Javascript because you have to keep adding plus operators (+) and quotes for every string you want to concatenate.

In React we use JSX (JSX is syntax used in React JS that looks like HTML), so we won’t be using template literals that much because we can easily include variables and expressions in the tags, but I think it’s an important feature.

Let’s see an example:

And if we have to add more strings or the strings include other characters like quotes, they need to be escaped with “\” then the code becomes more harder to read and error prone:

If we use template literals, then it will be a lot simpler. We need to add a backtick “`” (the key below the ESC key) to the beginning and end of the string and use “${}” for the variables:

You can also have multiline strings:

Map

The map() method is used to apply a function to every element in an array and return a new array.

Let’s say we have an array of user objects:

If we wanted to get the IDs of this users and assign them to a new array, we would do this:

But let’s see how we would do it in ES6 using map(). It would take us just one line of code:

map() is frequently use in React JSX to render list tags from an array, let’s see an example simulating JSX but as just a string:

 

Filter  (ES5)

The filter() method was introduced in ES5 not ES6, but I wanted to include it in this tutorial because you will see it everywhere in React code.

It creates a new array with all elements that pass the condition implemented by the provided function. In other words, if the function you pass to filter() returns “true”, then it will go to the new array.

If for example we wanted to get all the users that were deleted ( deleted = true) from the same array of users, we would do this:

Classes/Subclasses

Classes

For many years, Javascript developers have been emulating classes with functions, but classes are now finally included in Javascript with ES6.

Classes have been an important part of many languages. If you are familiar with other languages that support classes, then you should have no problem using classes in Javascript.

In React it’s common to have class-based components so that’s why it’s very important to understand how ES6 classes work and their syntax. A class is a template of an object. Object-oriented Programming (OOP) is a huge topic, so I will just show you here some very basic examples in Javascript.

To define a class, we use the “class” keyword and give it a name, which by convention should have the first letter capitalized:

Now let’s add some methods:

Subclasses

We can also have subclasses. Subclasses extend another class, so the subclass inherits the properties and methods of the original class.

You will see this a lot in React JS when you want to create a new Component:

Let’s create a new subclass called Student that extends from User.

But we will get an error if we do this because the subclass needs to always call super() in the subclass constructor:

By calling super(), we will call the parent class constructor method. This will allow us to use the “this” keyword in our subclass, and we could also add more properties and methods:

Modules

For years Javascript have been trying to implement different solutions for modules using third-party libraries. But now ES6 brings modules into Javascript natively. Modules provide a way to include functionality from one file into another. As a good practice, code should be split into smaller files.

Let’s say we have a file called math.js, and in that file we have a function called sum():

By using the “export” keyword, we could import that function (module) in another file. In this case, we have a file called app.js, and we use the “import” keyword followed by the module name in curly braces and then the “from” keyword to specify the location of the file. If the file is in the same folder, use “./” as a prefix:

A file can have multiple exports, but we can also specify a default export if we use the default keyword:

Now that we have a default export, we can import it without using the curly braces around the module name:

 

How to Get Rid of Your Household Chores and Get Things DONE When Working from Home

Household chores could be one of the nagging tasks you have to complete on a regular, everyday basis and of course, the longer you let them sit, the more pressing they have to be completed.

Not only is setting tasks and time management important to lead a productive lifestyle when working remotely, there are other aspects that can help you lead your work life and personal life smoothly.

Some tips won’t apply to you or your lifestyle, but I’m hoping that you can at least use a few of them to benefit your productivity.

I have some tips that can help you personally keep a better time management to balance both work and household chores, but also tips to help you make your life easier entirely, eliminating the necessity for you to complete the chores. These three lists of nine ways can help you maintain your household and your career at the same time.

Keeping Chore Households under Control

1. Have the Children Tidy up after Themselves

Children often are the sources of the majority of the mess in your household. One way that you can really reduce the amount of clean up that children cause is, no matter how old they are, to teach them how to clean up after themselves. From teaching them how to place their toys back to where they need to be or that their dirty clothes should simply be thrown into a basket. These are simple tasks that might take your kids to remember to get into a habit, especially the younger they are but are also great lessons to teach them about for when they get older.

Make it a game rather than rewarding them with an allowance.

I’m not here to tell you how to raise your children, but allowances really aren’t necessary. Teaching them that they have to be responsible in a fun way can make more of a lasting impression than rewarding them with money every time they pick up their toys. If you make it a game, it could even be fun for them, you might even see your children initiating clean up if they associate the chores as a fun game.

2. Delegate Tasks Out

To help delegate tasks to family members or other members of your household, you can set chores even through technology, like the Chore Buster App
Instead of simply assuming others know what they’re supposed to do, take advantage of the technology already in the hands of each of your family members. These Apps can help you delegate tasks and help remind, even you, to get them done. These Apps can be extremely effective and can take away the need for you to be the nagging one.
1. Giving your children or family members doable tasks throughout the house, even deeming pets as their personal responsibility not only takes those things off your shoulders, it can also teach them about having to get things done and time management. That way, you are taking care of the house, saving you time and effort, and teaching responsibility, all at the same time.

3. Tidy up as You Go about Your Day

Instead of doing all the necessary clean up tasks at the end of every day, try and clean up immediately after you or another family member uses something. If you just make it a habit to quickly take a few minutes to clean up right after, then those few minutes won’t accumulate at the end of the day to an hour, or hours of mundane, boring, and even tiring work. You can spray the shower or squeegee it immediately afterward, make your bed right in the morning after you wake up, fold your clothes right when they’ve come out of the dryer. This will not only help you have a clear mentality because it won’t leave you with a long to-do list but breaking the long list of tasks down into mini-tasks can help it seem more achievable and less painstakingly boring.
Wash, Dry and Put Dishes Away Immediately After Eating
This is just one of the tasks that you can do quickly and immediately after usage. If you break up the tasks into a family affair and assign each one of your family members a section of the assembly line, for example, one wash, one soap, one rinse, one dries, and one puts away, this can even feel like much less work.

4. Do Deep Cleaning and De-cluttering in Intervals

Pick a day of the month or however often you would like to get a deep cleaning done throughout the house and stick to it at intervals. This way, you can have your house clean as a whole, and your daily tasks or household chores requiring cleaning will be much shorter or require much less time. This will eliminate or reduce the necessary time for you to take time away from your remote, at-home career just to clean the house.
If you do this on Garbage Pick Up day, it’s perfect to throw away old food too.
On these cleanup days, you can line it up with the days that the garbage removal system comes around for your street, which is highly beneficial for your home, street, and environment. When you’re cleaning, make sure to check expiration dates on your food, throwing out expired food and clearing up space for new groceries.

5. Write a To-do List

Planning out what needs to get done and being able to cross it off a physical checklist can help you plan better and take care of your necessary household chores. This will help you also delegate tasks that need to get done to other household members or place them on a list for your to hire others to finish the tasks. You can do this every day, for the week, or even for the month for appointments that are not so often. This will help you with time management as well.

6. Meal Prep or Cook and Then Freeze

Since you need to eat every day and might need to cook for other members of your family or household, you can also eliminate the time during the week that you would spend doing this by meal prepping or doing the dishes on an every day basis. This can be done once a month and the meals are frozen and prepared for the day, or just one day at the beginning of the week, having the meals prepared and separated for everyday consumption. This tip will not only save you time to focus on your remote job but also money. The money you spend cooking or buying food every day can lead to impulse buying or restaurant prices.

7. Make a Timeline or Schedule Before the Week or Day Starts

This schedule, not just a task list, can help you plan your day or your week much better. Although we know that life happens and you can’t really carry out those plans minute by minute, it helps to have a bit of an outline (if you like that sort of thing), to follow to keep you on task to get the things done that you need to with the time you have. This timeline can either be just for you, including a schedule with your home and work life or both integrated or can involve your entire household.

8. Store Your Cleaning Supplies at Your Problem Areas

Such a minuscule change to make, but having your cleaning supplies exactly where you need it the most will not only eliminate the effort and time it takes to clean but also might remind you or encourage you to clean. For example, keeping bathroom cleaner underneath the bathroom sink, or your kitchen cleaning supplies underneath the kitchen sink might remind you and facilitate your effort when you just want to wipe down the counters or spray and clean the sink or toilet quickly.

9. Pay All Your Bills Online One Day in the Month

I don’t like to spend brain cycles every month thinking about if I missed a payment or that I have to waste precious hours going to banks. I have a Google spreadsheet listing all the bills I have to pay for the month ordered by due date, I use it as a checklist so I know exactly what I have to pay, when are my due dates and where I can pay online.

It looks something like this:

Google spreadsheet screenshot
I use a Google spreadsheet to keep track of all the payments for the month, I include a column for Notes where I put the URL I have to go to do the payment

Getting Your Household Chores Done with the Least Amount of Work as Possible

1. Hire Someone to Help You with Household Chores or Cleaning

There are so many services out there that you can outsource others to get the jobs done, which takes those tasks off of your to-do list but might cost you a bit of money. Of course, if you are working from home with a good salary, it should be a good investment, because it frees up that extra time for you to work when you would otherwise be getting those household chores done. Another reassuring fact about outsourcing household chores would be that you are at home most of the time working anyway, so if you have trust issues with other people in your home or with your children, you can keep watch on them as well as work.
Hire them at least once a month for deep house cleaning
Among many other tasks that I will lay out for you later on in this article, household cleaning is a common task that gets outsourced to be done at least once a month. This not only keeps your house tidy if done often — once a month, for example — it reduces the amount of time to keep the house clean throughout the month that you will most likely be doing on your own.

2. Get a Roomba and Program It to Do a Cleaning Cycle Every Morning

I just love my Roomba. I got my first Roomba initially to get rid of my wife’s hair but after we got our hairy cat (Tita) we started using it daily to clean up her hair and the day-to-day dirt and dust that gets tracked into the house.

I program it to automatically start cleaning every morning but usually Roombas get stuck on small things on the floor so make sure there’s nothing around that can get in her way like cords, shoes, etc.

A post shared by Carlos (@gigo6000) on

I currently own a Roomba 880 and I love it, is a lot easier to clean up than the previous one I had (Roomba 560)

3. Find Someone to Take Care of Your Kids

If you don’t trust anyone with the care of your family members, like your children, or pets, you can find a relative, such as their grandparents, or an aunt that can help take care of your kids. Try carpooling with family friends that you trust to eliminate the need to pick up your child from school or to and from extracurricular activities. Obviously, I’m not suggesting that you give up the joy it is to care and raise your children, but a little help goes a long way and the less you can spend (from your wallet, that is) when it comes to raising a child. After all, the saying goes: it takes a village to raise a child.

4. Automate Almost Everything You Can Do on a Reliable Time Schedule.

You can set your bills to be paid automatically by your bank on a certain day.
You can refill your prescriptions on a schedule and all you will have to do is pick them up.
You can mow the lawn automatically and vacuum the house with robots, such as the Neato Botvac and the Robomow, or have a mopping robot like the iRobot Braava.
You can even use a SmartFeeder to feed your pets automatically.
Technology has gotten so advanced, that for a price, you can pay to clean almost anything in your house with a cleaning robot. For example, you can clean the showers with the Automatic Shower Cleaner or squeegee after every use, you can clean the gutters with the Looj, and clean the windows, especially the ones up high, with the Winbot. Of course, watering the lawn with a sprinkler system has been done for ages.

5. Reminders on Your Phone Are Perfect for a Timed, Automatic Way to Help You Remember to Get Chores Done During the Day.

Think of this as your personal assistant without having to outsource and pay for one (see below). This is a simple, automated way that can help you manage your time and plan tasks or household chores around your work. Breaking them up into small segments of time can also make them seem more achievable.

6. Have Your Weekly Groceries Delivered to You with an Online Grocer, or Your Meals Picked up for You with UberEats

An online grocer can be outsourced, not only can you outsource it with the service called Dream Diners, you can even do online shopping and then get it delivered right to your door, or pick them up at the grocery store after they were done for you.

7. Eliminate Some Shopping by Using Services Where Your Groceries or Personal Items Are Delivered Right to Your Door. For Example, Amazon’s Subscribe and Save Program.

Not only can you get this task done online for your grocery shopping, you can also turn to this task with your everyday items, like toilet paper and tampons. An example of this sort of program is Amazon’s Subscribe and Save Program. Not only do you get your shopping done in the easiest way, you can also save money doing it since they offer specials or reduced prices for members.

8. Laundry Services That Offer Pickup and Delivery.

Laundry is already so automated with machines that are so technologically advanced when it adds the detergent or dryer sheets for you. But there are laundry services that offer pick up of your dirty clothes and deliver them back, right to your front door, when they are washed and cleaned for you. Of course, this includes special services like ironing and delicate clothes that require specific cleaning methods.

9. Have Your Pet Adjust to the Litter Robot, Which Eliminates the Need to Empty It out as Often.

This is also another great technological advancement that can eliminate the task of cleaning up after your pet or reduce it down to once every couple days when the machine is full.

For 89 different, highly technologically advanced inventions that can help you make your household chores easier, here is a list: https://www.trendhunter.com/slideshow/household-chores-easy

Of course, you should be willing to pay a bit out of pocket for these genius machines that will save you a lot of time in the long run.

If you aren’t willing to buy all those technologically advanced robots for fear of something playing out like the plot in I, Robot, you can stick with human help.

Not only can you hire someone to clean your house for you, people can also work in a variety of different chores.

These people have a variety of titles, ranging from HomeCare to House Manager.
They can help you maintain care and order around your house, being responsible for tasks ranging from cleaning to supervising pregnant young women or older people to ensure they meet appointments and other responsibilities.

Here are a few tasks that can be met by outsourcing and taken care of while you work remotely.

Outsourcing Household Chores:

1. Help Prepare Breakfast or Cook

Having someone cook in your house can free up some time for you and get you the food you and your family needs to eat. Especially if you’re not that great of a cook, this can be a good investment. This is also a great alternative to someone who doesn’t want to spend the extra money on take-out. You can also better control what goes into our food and make it healthier, rather than relying on fast food to fulfill your family nutrition.

2. Maintain Calendars for Appointments and Extracurricular Activities

Having someone maintain a family calendar will not only keep your household members more accountable but will also help them realize that they need to get it done. If you have children or spouses with a lot of extracurricular activities, then writing it all down on a calendar will help your chances of never forgetting an appointment, practice, or special event. For a job like a nanny, this is perfect to have when for your kids.

3. Help Manage Food Budgets and Other Household Budgets

Someone taking control of your finances gives you the peace of mind that everything is taken care of and is one less thing to take care of. For those who also are not so savvy with numbers, this can help give you less stress in that area of your financial budget.

4. Drop off and Pick up Children from School and Extracurricular Activities (as Easy as a School Bus)

If you trust whoever you hire, they can help you drive to and from your child’s school or extracurricular activities. If you don’t want to spend the extra money, you can help arrange a carpool shift with your neighbors or children’s friends (their parents, of course), that can work out best for everyone.

5. For Odd Jobs, There Are Websites like TaskRabbit and Angie’s List

Instead of spending an ample amount of your time trying to figure out to fix a sink because you don’t trust the guy who did your plumbing last time, you can check out TaskRabbit or Angie’s List, which are sites that outsource odd jobs that have been a nuisance around your house and can get them done for a good price with some trustworthy people. Most of these workers are reviewed and graded, so their quality and price are no secrets.

6. Lawn Services

Instead of buying one of those pricey mowing robots I mentioned earlier, you can outsource the need or task to mow your yard or care for your garden. Whether it is the kid down the street looking for a few extra bucks to push your lawn mower around or it’s a professional lawn service, this task and household chore can easily be outsourced with a reliable worker.

7. House Cleaning

As stated before, it is recommended to hire a house cleaner at LEAST once a month to really maintain a clean house for the majority of the time. If you get someone to do a deep house cleaning once a month, this also reduces and eliminates the usual cleaning during the week or the rest of the month. This will also leave your family happier and healthier because there are a lot of negative effects of a dirty, or unclean house.

8. A Personal Shopper or Personal Dresser

You can easily hire someone to do your shopping for you. Whether it is grocery shopping or shopping for the abnormal oddities, even picking up dry cleaning, there is someone you can hire that will get the job done for you. There are even people that can help figure out your professional outfit for you and go shopping for you with your clothes and shoe sizes. This can help save you time that you could or would rather be working. Although these services cost money, as I stated earlier, you can be working and earning money during the time that these tasks normally would take.

9. In General, Hiring a Personal Assistant

Within reason, some people are willing to do the most abnormal tasks for you to do, without even batting an eyelash. For whatever task you may need, there is usually someone that you can hire that would be willing to do it. This means hiring a personal assistant. Contrary to popular belief, personal assistants have been more normal than say, ten years ago, and can help you anywhere from your financial or business assistance, to personal assistance, like maintaining your budget, social media pages, the sky is the limit.

There are so many ways to get your household chores done without having it get in the way of building or maintaining your successful career which you care for remotely. Choosing to work from home or from wherever you are is an opportunity to shed other responsibilities, but is only done in vain if those responsibilities are replaced quickly with household chores.

Working from home should improve your productivity and lifestyle. You will be able to set your own hours, get the tasks done when you can, and spend as much time as you need on your projects. However, life does get in the way and when you are working from home, you don’t really have an office to get away from it all. Therefore, those pesky household chores and tasks are always staring you in the face.

However, if you try some of these ideas or purchasing some of these products or services, you can eliminate some of those household chores, all while getting the work and productivity done that you need to have and maintain a successful career.

I hope this list has helped give you ideas to reduce or eliminate the time you need to do household chores and increase the time you have for what’s more important to you, being either your work or your family and personal life.