Swapna Kumar Panda ๎จ€ Profile picture
Jan 31 โ€ข 14 tweets โ€ข 4 min read
๐Ÿฆพ 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

Jan 30
JavaScript Interview Questions

โ‡ฉ
Series: 1๏ธโƒฃ
Level: Beginner
Topics:

โžŠ Data Types
โž‹ Boolean
โžŒ Number
โž Logical Operators
โžŽ Comparison Operators
โž Arithmetic Operators
๐Ÿšฅ Disclaimer

โฌ– The questions covered here are mostly conceptual
โฌ˜ I never claim only these type of questions are/should be asked during interviews
โฌ— For interviews, you should have fundamentals strong. And you should be able to provide solutions to practical problems.
Read 14 tweets
Jan 29
๐Ÿšฅ 22 HTML Input Element Types
There are total 22 "input" types in HTML.

โ‡ฅ text
โ‡ฅ password
โ‡ฅ search
โ‡ฅ url
โ‡ฅ email
โ‡ฅ tel
โ‡ฅ number
โ‡ฅ button
โ‡ฅ submit
โ‡ฅ reset
โ‡ฅ file
โ‡ฅ checkbox
โ‡ฅ radio
โ‡ฅ range
โ‡ฅ datetime-local
โ‡ฅ month
โ‡ฅ week
โ‡ฅ time
โ‡ฅ date
โ‡ฅ hidden
โ‡ฅ color
โ‡ฅ image
โš ๏ธ Message โš ๏ธ

I have compiled these information with all sincerity. But in case you find any omissions or, wrong presentations, please inform me.
Read 4 tweets
Jan 26
How is Math.min() > Math.max() ?

A JavaScript ๐Ÿงต
โžŠ Background

โฌ” Try to execute below in console.

โ‡ฅ Math.min() > Math.max()

โฌ“ You will be surprised to see the result "true".

โฌ• How can min() be more than max()? Is it weird?

Let's find out.
โž‹ Variadic Function

โฌ” A function is called "variadic" when it can handle variable number of arguments.

โฌ• Both Math.min() and Math.max() can handle any number of arguments including "Zero".
Read 10 tweets
Jan 25
SQL & RDBMS Interview Questions

โ‡ฉ
Series: 1๏ธโƒฃ
Level: Beginner
Topics:

โžŠ Introduction to RDBMS
โž‹ Normalisation
โžŒ Introduction to SQL
โž Tables and Fields
โžŽ Constraints
โž DML Operations
โž Joins
๐Ÿšฅ Disclaimer

โฌ– The questions covered here are mostly conceptual
โฌ˜ I never claim only these type of questions are/should be asked during interviews
โฌ— For interviews, you should have fundamentals strong. And you should be able to provide solutions to practical problems.
Read 13 tweets
Jan 24
~11000 friends in [CHIRPBIRDICON], ๐Ÿคฉ

If you are interested in,

๐ŸŒ HTML
๐ŸŽจ CSS
๐Ÿ‘ฉโ€๐Ÿ’ป JavaScript
โš›๏ธ React
๐Ÿ›  DSA
๐Ÿ›ข SQL/NoSQL

Follow me โœ…

I am sharing contents daily in [CHIRPBIRDICON] which you won't want to miss. ๐Ÿงตof pointers to all those, ๐Ÿ‘‡
๐ŸŒ HTML ๐ŸŽจ CSS

twitter.com/i/events/14854โ€ฆ
๐Ÿ‘ฉโ€๐Ÿ’ป JavaScript

twitter.com/i/events/14854โ€ฆ
Read 7 tweets
Jan 23
๐Ÿ’› CSS: border-radius

Explained with Classic Illustrations
๐Ÿ“‹ Table of Contents

โžŠ Introduction
โž‹ How to specify?
โž‹.โž€ One/Two/Three/Four Values
โž‹.โž Percentage Value
โž‹.โž‚ Horizontal and Vertical Radius
โžŒ Other Related Properties
โž Shapes using border-radius
โžŽ Conclusion
โžŠ Introduction
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!

:(