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.


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💚Code Life Fitness

Ankur💚Code Life Fitness 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!


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

28 Sep
Complete roadmap to decode your next Front-end Interview Process.

A Thread... 🧵

#100DaysOfCode #CodeNewbies
🚀 Process for a front-end development interview will vary from different companies sometimes.

Interview is a different game that takes practice.

Often big developers fail due to lack of presentation & communication skills.
🎙To understand the e2e process is mandatory.

Front-end development interview process & few tips to have successful interviews.

Understand the main weapons you work with (HTML, CSS, JavaScript)
Read 15 tweets
28 Sep
How to land your first job as a web developer👇

Whether you’re self-taught, a Bootcamp grad, or have a college degree, when you’re a fresh-faced web developer, landing that first job can be tricky.

A Thread 🧵

#100DaysOfCode #CodeNewbies
🔈 Getting started into programming can be very scary, and there are a lot of misconceptions out there that make people think that programming is a skill they could never learn, or that landing a job as a web developer is almost mission impossible.
🔈 The software development industry, web development, in particular, is full of amazing stories of people with no tech background who switched to development and changed their life for great.
Read 35 tweets
26 Sep
Top social media pitfalls

A Thread...
1- Quit Copying ASAP

There's nothing social network users love more than exposing unoriginal activity when they spot it, so don't copy other people's work.

This may seem like a no-brainer, but many dev/humans are often tempted to cut and paste.

2- All About Your Personality

> Don't join Twitter without thinking about the commitment.

If you have a clearly defined brand then you may want to create both a personal and professional persona.

😎"Your personality is your brand"
Read 10 tweets
25 Sep
Top cooperate life lessons for you. (GOOD OR BAD)

* Good or bad, you will have every type in your team

* No one doesn't really care about you

* Nobody is your friend

* Find a healthy competitor, not a friend, so that you can grow.

Thread 🧵
* 80 % just works for promotions & become YES man.

* Build your knowledge, companies will follow you.

* Don't be that person in a team, who always available

* Learn to say no, maximum fail here

* Politely leave the meeting if you are not contributing.
* Don't check & reply mails in the first 1 hour of your day.

* If it's really urgent, a person will call you.

* Don't believe in a verbal promise (99.99- FALSE)

* Take everything in writing

* Ask for feedback if you are not getting.
Read 7 tweets
24 Sep
Is Javascript Good For Machine Learning?

Can I do Machine Learning with JavaScript?

The short answer is yes.

I did some research here are the findings 👇

Thread 🧵

#100DaysOfCode #javascript #CodeNewbies
Few things that are said about JavaScript when it comes to Machine Learning.

- Javascript is slow.
- Handling Matrices is difficult with JavaScript.
- Python got all the major libraries.
Python got all the major libraries 👇

Yes. all the important libraries for M.L. in which much of the study and research has been done, are made in Python.

For e.g. 👉 TensorFlow and scikit-learn.
Read 9 tweets
23 Sep
Awesome Javascript Games and Js Software to Create Games

Thread 🧵

The best site for game development👇

>js13kGames 2019 - Highlights from the js13kGames 2019 competition.

>js13kGames 2018 - 13 Games in ≤ 13kB of JavaScript.

>js13kGames 2017 - Build a game in 13kB or less with js13kGames.
Adventure Game 👇

Triangle: Back To Home


Dwarfs: There and Back Again

Bounce Back:

Offline Paradise:

Read 9 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

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

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!