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

Apr 22
How did I master Python in 12 months?
Here's how I made it.

➊ Knowing the History
➋ Knowing the Ecosystem
➌ Managing the Operating System Challenge
➍ Learning the language

Keep reading.
📖 Preface

⬘ I have been into programming for >20 years. But, my interaction with Python happened in 2021.

⬗ Learning a new language wasn't new for me as I have done that so many times.

⬙ I prepared my own roadmap and tried to keep it very simple.
Read 19 tweets
Apr 15
SQL opens the door for multiple career options.

Master these 10 key SQL topics and you are ready to ———
➊ Fundamentals

➀ What is a database and DBMS?
➁ What is a relational database?
➂ What are some popular RDBMS?
➃ What is normalization?
➄ Different normalization forms (NFs).
➅ What is SQL?
➆ Different components of SQL.
➇ What is ERD?
➋ Working with database/table

❯ Create a database
❯ Create a table
❯ Alter a table
✧ Add a column
✧ Remove a column
✧ Modify a column
✧ Rename a table
❯ Drop a table
❯ Various Datatypes
❯ Constraints
✧ Primary Key
✧ Foreign Key
✧ NOT NULL data
✧ UNIQUE data
Read 12 tweets
Apr 11
👩‍💻 150+ Algorithms asked in Interviews

Practice in
❍ C++
❍ Java
❍ Python
❍ JavaScript
Or, any language of your choice

➊ Array - Algorithms

➀ Creating an Array
➁ Iterate through Array
➂ Get an Element
➃ Search an Element
➄ Insert Element(s)
➅ Delete Element(s)
➆ Filter an Array
➇ Fetch a Sub-Array
➈ Merging Arrays
➉ Reverse Array
➀➀ Rotate Array
➋ Linked List - Algorithms [1]

➀ Creating a Linked List
➁ Iterate through Linked List
➂ Get an Element
➃ Find an Element

➤ Insert Element(s)
➄ At Start
➅ At End
➆ At Anywhere
Read 18 tweets
Apr 1
Python opens the door to multiple career options.

9 key topics you should master to be an Expert:
➊ Simple Data Types

Effort: 1 to 2 hours daily + Normal practice

❯ Boolean
⬩bool
❯ Number
⬩int
⬩float
⬩complex
❯ String
⬩str
❯ Bytes
⬩bytes
⬩bytearray
⬩memoryview
➋ Operators, Conditions, and Loops

Effort: 1 to 2 hours daily + Normal practice

❯ Operators
⬩Arithmetic
⬩Assignment
⬩Comparison
⬩Logical
⬩Precedence
⬩Associativity
❯ Conditionals
⬩If
⬩Else
⬩Elif
❯ Loops
⬩while
⬩for
Read 11 tweets
Mar 30
Remote software jobs paying in USD

Check this out:
➊ WWR

🖇️

Over 4.5M people visited it to find a remote job.

⬩Front end
⬩Back end
⬩Full-stack
⬩DevOps
⬩Marketing
⬩IT Support
⬩Management weworkremotely.com
Image
➋ Flex Jobs

🖇️

25K+ featured jobs. 5K+ companies.

Great chance to get the flexible remote job that you are looking for.

⬩Development
⬩Analyst
⬩Data Entry
⬩Call Center
⬩Accounting
⬩IT Support flexjobs.com
Image
Read 12 tweets
Mar 29
If you have Python interview in just 6 hours,

This is how you can prepare:
➊ Don't panic

⬘ List down all the things (mentioned in subsequent tweets of this thread).

⬗ Keep your phone in silent and airplane mode.

⬙ Keep 2 ltr of water and some snacks/food.
➋ Review core topics

⬘ Open the notes you have taken or, the book you have followed.

⬙ Check this thread for all the core topics and quickly review all that you have learned.
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!

:(