Ankur💻🎧💪 Profile picture
Sep 13, 2020 18 tweets 4 min read Read on X
Top JavaScript developer stuff to blow YOUR mind.

JavaScript has grown way beyond the browser since Node.js enabled JavaScript to be run on the server.

Let’s take a look at some of my favourite JavaScript tips, tricks.

#100DaysOfCode

Thread 🧵
1. Write tomorrow's JavaScript today with Babel

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:

[4, 7, 2, 3].filter((num) => num % 2 === 0); // [4, 2]
7. Use 'reduce' instead of 'for' loops

For this exercise,

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
 

Keep Current with Ankur💻🎧💪

Ankur💻🎧💪 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 @TheAnkurTyagi

Dec 16, 2022
How do you decide which early-stage startup to join?

A thread. Photo by Melissa Keizer on Unsplash.
There are key factors to consider when choosing the early-stage start-up you'll join:

- The Team
- The Market
- The Product
- The Culture
- The Stage of the Company

The decision to join a start-up should be based on a combination of these factors and your personal goals.
As a developer in an early-stage start-up, you have to truly believe in its mission as you’ll be so involved in it.

Therefore, you need to assess the relevance of the project for you (and its viability) before joining the company.

To do so, focus on these 3 specific aspects 👇
Read 9 tweets
Dec 13, 2022
I made $50K+ from blogging in the last 2 years working as a part-time writer.

Here’s everything I learned.

A thread. Image
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?

Play not to lose; Instead to win.
Read 12 tweets
Oct 4, 2022
If you're starting a career in software engineering.

Here are 22 top life lessons for you from my career:

A Thread... Here are 22 Top life lessons for you from my career:
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.
Read 7 tweets
Jul 23, 2022
How to Find a Good JavaScript Developer...

A Thread.
As with any technology, there’s knowing JavaScript and then there’s really knowing JavaScript.

Let me share a couple of proven & effective techniques and questions for finding true masters of the language.

Note:
These sample questions are intended merely as a guide.
🚨 Alert 🚨

Not every candidate worth hiring will be able to properly answer them all, nor does answering them all guarantee a candidate.

At the end of the day, hiring remains as much of an art as it does a science.

JS is in the world of tech today has become fundamental.
Read 12 tweets
May 31, 2022
I completed 12 years as a software developer in 2022.

Few honest takeaways about my experience with the job and the software engineering industry.

A Thread...
1. No one can stop you when you master the basics

- You can start with any technology you want.

But if you’re struggling, take a pause & restart your tech journey.

- Remember all new & fancy frameworks are based on the basics.

- Master basics you can code in anything.
2. “What's more important to you: Quantity or Quality?”

- Your answer might be: it depends.

But until you do an experiment in your core areas, how do you actually know about the quality.

Go & take calculative risk & be the change.
Read 13 tweets
Mar 16, 2022
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
Read 13 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

Don't want to be a Premium member but still want to support us?

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

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us!

:(