Swapna Kumar Panda Profile picture
Oct 13, 2021 12 tweets 4 min read Read on X
🔥 9️⃣ Useful Hacks to simplify your JavaScript code

Follow these simple yet most useful hacks in your code. These are not only modern way of writing JS code but also minifies your code.

🧵 👇
We will cover,

1️⃣ Converting to Boolean
2️⃣ Converting to Number
3️⃣ Converting to String
4️⃣ Short-Circuit && and ||
5️⃣ Default Function Parameters
6️⃣ Nullish Coalescing Operator
7️⃣ Optional Chaining Operator
8️⃣ Array Resizing
9️⃣ Converting Array-Like to Array
1️⃣ Converting to Boolean

To convert any data to a Boolean type, use

→ Boolean function or,
→ !! operator
2️⃣ Converting to Number

To convert any data to a Number type, use

→ + operator or,
→ Number function or,
→ parseInt function
3️⃣ Converting to String

Use String function when you need to convert any data to a String type.
4️⃣ Short-Circuit && and ||

Instead of using traditional if-condition statements, try to use short-circuit && or, ||

Use this trick only when the expression inside "if" is just a one-liner expression or a simple function.
5️⃣ Default Function Parameters

To assign missing values on function parameters, instead of using || operator, use default function parameters.
6️⃣ Nullish Coalescing Operator

Instead of manually checking whether an input is either null or, undefined, use nullish coalescing operator (??).
7️⃣ Optional Chaining Operator

To avoid TypeError, instead of checking whether a property exists in an object manually, use optional chaining operator (?.)
8️⃣ Array Resizing

To remove few last elements from an array, simply modify the array's length property value. Items from the array will automatically be removed.
9️⃣ Converting Array-Like to Array

An Array-Like object is like an Array which has a length property and, can be iterated like an array.

E.g., arguments inside function body, a string object etc.

Use Array.from() or, spread operator to convert Array-Like to an Array.
That's it guys. Did you find these hacks useful and interesting?

Reply any additional hacks you are aware of. Share me your feedbacks as well.

See you in next 🧵 soon. 👋

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Swapna Kumar Panda

Swapna Kumar Panda 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 @swapnakpanda

Mar 12
If you are a software engineer who wants to upskill in system design, bookmark these 13 sites:
2. System Design Primer

github.com/donnemartin/sy…Image
Read 14 tweets
Mar 10
I wish these Mathematics Courses were available during my School Days.

10 completely free courses for Beginners:
Read 11 tweets
Feb 27
Stanford's FREE Courses on AI & ML:

❯ CS221 - Artificial Intelligence
❯ CS229 - Machine Learning
❯ CS230 - Deep Learning
❯ CS234 - Reinforcement Learning
❯ CS224N - NLP with Deep Learning
❯ CS336 - LLM from Scratch

All 11 course links inside:Image
1. CS221 - Artificial Intelligence

🖇 youtube.com/playlist?list=…Image
2. CS229 - Machine Learning

- By Andrew Ng

🖇 youtube.com/playlist?list=…Image
Read 11 tweets
Feb 19
JavaScript is MUST in 2026.

This is how you can MASTER it in 6 months:
➊ Fundamentals

Effort: 1 to 2 hours per day
Time: 2 weeks

➀ JavaScript Engine
➁ JavaScript Runtime
➂ Execution Context
➃ Hoisting
➄ Call Stack
➅ Event Loop
➆ Callback Queue
➋ Variables and, Datatypes

Effort: 1 to 2 hours per day
Time: 2 weeks

➀ Datatypes
❯ Primitives
❯ Literals
❯ Numeric
❯ Boolean
❯ String

➁ Variable
❯ Naming
❯ Declaration (var, let, const)
❯ Assignment

✧ Special Topic
❯ Type Coercion
❯ undefined, null, NaNImage
Read 17 tweets
Jan 29
AI/ML Courses from Stanford (ALL FREE):

❯ CS221 - Artificial Intelligence
❯ CS229 - Machine Learning
❯ CS230 - Deep Learning
❯ CS234 - Reinforcement Learning
❯ CS231N - Deep Learning for CV
❯ CS336 - LLM from Scratch

Course links inside 👇Image
Image
Image
Image
1. CS229 - Machine Learning

- By Andrew Ng

🖇 youtube.com/playlist?list=…Image
2. CS230 - Deep Learning

- 2025 (Ongoing)
- By Andrew Ng

🖇 youtube.com/playlist?list=…Image
Read 12 tweets
Jan 4
Stanford's ALL FREE Courses (AI & ML):

❯ CS221 - Artificial Intelligence
❯ CS229 - Machine Learning
❯ CS230 - Deep Learning
❯ CS234 - Reinforcement Learning
❯ CS336 - LLM from Scratch
❯ CS224N - NLP with Deep Learning

Course links inside 👇Image
Image
Image
Image
1. CS229 - Machine Learning

- By Andrew Ng

🖇 youtube.com/playlist?list=…Image
2. CS230 - Deep Learning

- 2025 (Ongoing)
- By Andrew Ng

🖇 youtube.com/playlist?list=…Image
Read 12 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!

:(