Babel allows developers to write code using the latest version of JavaScript without sacrificing compatibility with older browsers
This transforms ES2015 code into a normal ES5 JavaScript code that browsers are able to interpret.
2. Cool new ways of declaring variables
In ES2015, JavaScript introduced two new ways of declaring variables: let and const.
>let is used when a variable will be reassigned
>const keeps a variable from being reassigned.
IMP Note:
const does not freeze arrays and objects.
let and const are scoped to their closest block, allowing developers to declare variables within if, while, for, and even switch blocks, without worrying about the variable scope leaking outside of that context.
JavaScript, the most commonly used language by StackOverflow 2020
3. Use arrow functions to keep 'this' intact
These have ability to keep "this" context intact,
especially when using it within callbacks that might get called from somewhere else (i.e. adding an event listener with jQuery).
arrow functions replace the need to add .bind(this)
There are two main ways of writing arrow functions:
one-liners and multiple-liners.
For e.g.
// let doubleShort = (num) => num * 2;
let doubleLong = (num) => {
let doubleNum = num * 2;
return doubleNum;
}
4. Use promises to avoid a callback can of worms
Promises solve this problem by helping you execute code in a concise manner, while keeping operations asynchronous.
you tell the code to do something, then something else,
& you’re even able to catch errors along the way.
5. Replace 'for' loops with 'map' to keep things simple
Let’s pretend we have an array of numbers and we’d like
to produce another array by doubling all of the numbers
from the first array.
One way to do this is to declare an empty array 👇
write a for loop, and set a number in the 2nd array by looking up the index on the first array and doubling it.
Or we could use a more concise solution by mapping an array to another array:
[1, 2, 3].map((num) => num * 2); // [2, 4, 6]
6. Replace 'for' loops with 'filter'
This time, let’s pretend we have an array of numbers and we’d like to produce another array containing only the even numbers from the first array.
Again, one way of doing this would be to declare an empty array, write a for loop, 👇
and write an if statement to check if the number at the index is even.
Or, we could use the filter method available for arrays:
let’s calculate the sum of all of the numbers in an array.
One way to do this would be to declare a variable that has zero as its initial value.
Then, we would write a for loop and traverse our array,
Or we could use the reduce method:
[7, 2, 4].reduce((a, b) => a + b); // 13
Can use all 3 concepts by multiplying all the nums by 7 & adding all the numbers that are smaller than 20
[3, 2, 1, 6]
.map(num => num * 7)
.filter(num => num < 20)
.reduce((a, b) => a + b); // 21
8. Take advantage of immutability
Data immutability is a common concept in functional languages
by default, objects and arrays are not immutable in JavaScript,
there is a library to help accomplish this, called Immutable.js and it was developed at Facebook.
9. Node.js: Avoid switching language context
Node.js is what allows JS to be used on the server-side.
interesting side effects, like making dev crazy-productive because you don’t have to change the language context when switching back and forth between client and server code.
10. NPM: largest package manager
npm (the node package manager) has become the biggest package manager in the world,
containing more packages than Java’s Maven Central Repository, PHP’s Packagist, and even .NET’s nuget.
It contains over 300 thousand packages.
11. Go beyond 'console.log'
Using console.log() to display data in the console while writing JavaScript apps is pretty common,
but did you know you can use other console methods – such as dir() and table() – to help you visualize data while developing?
That’s right;
for a more interactive way of visualizing objects in the console,
use console.dir(object).
If you have an array of objects you’d like to visualize,
you can use console.table(array) to create a beautifully formatted table displaying all your data.
Hope this helps 💙🙏
• • •
Missing some Tweet in this thread? You can try to
force a refresh
I made $50K+ from blogging in the last 2 years working as a part-time writer.
Here’s everything I learned.
A thread.
The only writing (blogging) hack you should know:
- Less tech is more, I work with React 90% of the time.
- If you’re writing for the first time, give yourself more time to figure it out.
- Allow yourself to write poorly.
Stop preparing and start acting.
Ask yourself questions which will help you be focused:
- Who do I need to send a cold DM/Email to?
- What do I do better than other writers in tech?
- What can I do for a long time in blogging?
- Where do I want to take my blogging skills?
If you're starting a career in software engineering.
Here are 22 top life lessons for you from my career:
A Thread...
1. No one doesn't really care about you. 2. Nobody is your friend. 3. Find a healthy competitor, not a friend, so that you can grow. 4. Learn to say no, maximum fail here. 5. Build your knowledge, companies will follow you.
6. 80 % just work for promotions. 7. Don't be that person in a team, who is always available. 8. Learn to leave the meeting if you are not contributing. 9. Don't check & reply to emails in the first 1 hour of your day. 10. If it's really urgent, a person will call you.
Things I Wish I'd Known Before Starting My First Full-Time Job.
A Thread...
Your 20s could be your most defining decade
You’ll have more freedoms & more choices than you’ve ever had in the past or will ever have in the future.
It’s going to be a great adventure.
The “real tech world” that everyone tries to scare you about is actually really awesome.
But you know:
-Don’t be afraid to learn on the job.
-Don’t pretend to know more than you actually do
-You're responsible for your career, not your employer
-Everything is negotiable
-Live to work, but the right Way
-Working late is overrated
-The grass will always be greener