Swapna Kumar Panda Profile picture
Jan 31, 2022 โ€ข 14 tweets โ€ข 4 min read โ€ข Read on X
๐Ÿฆพ 11 Modern JavaScript Hacks

โ‡ฉ
๐Ÿ“‹ Table of Contents

โžŠ Conversion to Number
โž‹ Conversion to Boolean
โžŒ Conversion to String
โž Complex String
โžŽ Short Circuit && / ||
โž Nullish Check
โž Default Value
โž‘ Default Function Parameter
โž’ Optional Chaining
โž“ Array Resizing
โžŠโžŠ Function Rest Parameter
โžŠ Conversion to Number

To convert any data to a Number type, use

โ‡ฅ Unary "+" operator
โ‡ฅ Number function
โ‡ฅ parseInt function
โž‹ Conversion to Boolean

To convert any data to a Boolean type, use

โ‡ฅ Boolean function
โ‡ฅ !! operator (Double Bang Operator)
โžŒ Conversion to String

Are you converting a value to a String like below? Remember, it's faulty.

โ‡ฅ '' + input

Instead use String() function.
โž Complex String

Are you forming a String using multiple concatenation operators? Remember, it's difficult to write and hard to read.

โ‡ฅ 'Hello ' + fName + ' ' + lName

The modern approach is to use String Template Literals.

โ‡ฅ `Hello ${fName} ${lName}'
โžŽ Short Circuit && / ||

Are you still using "if" statements for one-liners?

โ‡ฅ if (hungry) eat()

The modern approach in such scenarios is to use Short-Circuits.

โ‡ฅ hungry && eat()
โž Nullish Check

How do you check Nullish values?

The modern and most effective way is doing it using "Nullish Coalescing Operator" (??)
โž Default Value

How do you assign value to a variable if it's missing?

โ‡ฅ x || (x = 10)
โ‡ฅ y ?? (y = 10)

The modern approach of doing it is

โ‡ฅ x ||= 10
โ‡ฅ y ??= 10
โž‘ Default Function Parameter

Do you often check if a function parameter is missing its value and manually assign a value to it?

The modern approach is to use default function parameters.
โž’ Optional Chaining

To avoid TypeError, instead of checking whether a property exists in an object manually, use "Optional Chaining Operator" (?.)
โž“ 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.
โžŠโžŠ Function Rest Parameter

Are you using "arguments" variable to manipulate your function parameters? The modern approach is to use a "rest parameter".
End of ๐Ÿงต

Are you looking for modern tricks for web development? I am sharing those on HTML/CSS, JavaScript and React regularly.

If you are interested, Follow me โœ…

โ€ข โ€ข โ€ข

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!

:(