Swapna Kumar Panda ๎จ€ Profile picture
Mar 17 โ€ข 16 tweets โ€ข 5 min read
๐Ÿฆพ 11 Modern JavaScript Hacks

โ‡ฉ
๐Ÿ’ญ Why is this Thread?

โ‘ The code we write should be readable and, maintainable. But that doesn't mean it should be verbose.

โ’ With ECMAScript new specifications, many newer syntaxes are available which we should try to use mostly.

โ‘ Let's explore few such modern tricks.
๐Ÿ“‹ 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".
โš ๏ธ Repost Notice โš ๏ธ

โฌ˜ Though this is my original work, most of these tricks are previously shared by me in [CHIRPBIRDICON]

โฌ™ If you liked this content and do feel others might learn from it, please support.
End of ๐Ÿงต

Hey ๐Ÿ‘‹ I am a Tech Educator from India ๐Ÿ‡ฎ๐Ÿ‡ณ

I am sharing Tutorials, Tips, Techniques, Infographics, Cheat Sheets, Interview Questions and Roadmaps on Web Development, DSA and, Database.

Are you interested? I am sure, you are.

To never miss anything, 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 19
๐Ÿ’œ JavaScript: Array's length vs String's length
-
โ‡ฉ Array's length property is ...
โžŠ Introduction

In JavaScript,

โœง Array is an Object whereas String is a primitive

โœง Despite String being a primitive, for easy operations it has a lot of methods and, properties

โœง String is considered as Array-Like

โœง Both Array and, String has a "length" property
โž‹ Array's length

โœง Unlike many other languages, JavaScript actually allows to modify an array's length manually.

โœง If we set a larger length, few blank spaces (holes) are added to the end.

โœง If we set a smaller length, elements are removed from the end.
Read 7 tweets
Mar 18
๐Ÿ”  CSS Font Related Properties & Values Image
๐ŸŒ† Direct Link for High Resolution Image

If you liked this one, give a โญ๏ธ to this GitHub repo to support my work.

โœง Direct Link:
github.com/swapnakpanda/Iโ€ฆ
๐Ÿ“‹ Properties we covered

โžŠ font-family
โž‹ font-size
โžŒ font-weight
โž font-style
โžŽ font-variant
โž text-decoration
โž text-transform
โž‘ color
Read 14 tweets
Mar 16
60+ Shorthand Properties : CSS Cheat Sheet

โ‡ฉ
๐ŸŒ† Direct Link for High Resolution Image

If you liked this one, give a โญ๏ธ to this GitHub repo to support my work.

โœง Direct Link:
github.com/swapnakpanda/Iโ€ฆ
Read 10 tweets
Mar 15
Why <!DOCTYPE html>?

โ‡ฉ
โžŠ History

โœง In the old days of the web, pages were written in two versions: One for Netscape Navigator, and one for Microsoft IE.

โœง When the web standards were made at W3C, browsers could not just start using them, as doing so would break most existing sites on the web.
โœง Browsers therefore introduced two modes to treat new standards compliant sites differently from old legacy sites.

โœง Modes were: Quirks Mode and Standards Mode.

โœง For HTML documents, browsers use a DOCTYPE in the beginning of the document to decide which mode to handle.
Read 12 tweets
Mar 14
๐Ÿ›ฃ Beginner's Roadmap for Front-End

HTML & CSS โ†’ ๐Ÿ‘ฉโ€๐Ÿ’ป โ†’ JavaScript โ†’ ๐Ÿ‘ฉโ€๐Ÿ’ป
โ†“
๐Ÿ‘ฉโ€๐Ÿ’ป โ† React* โ† ๐Ÿ‘ฉโ€๐Ÿ’ป โ† Tailwind*
โ†“
TypeScript โ†’ ๐Ÿ‘ฉโ€๐Ÿ’ป โ†’ Next.js* โ†’ ๐Ÿ‘ฉโ€๐Ÿ’ป โ†’ ๐Ÿ

โ‡ฉ
๐Ÿ’ญ Why is this thread?

โ‘ Beginners willing to start their Front-End journey are often get confused about what all they have to learn and explore.

โ’ This is my honest attempt to help them by sharing a clear roadmap.

โ‘ It is from my 15 years of Web Development experience.
๐Ÿ“‹ Table of Contents

โžŠ HTML & CSS
โž‹ JavaScript
โžŒ CSS Frameworks
โž UI Frameworks
โžŽ TypeScript
โž Server-side Frameworks
โž Others
โž‘ What is essential?
Read 17 tweets
Mar 13
25 super useful methods in JavaScript

โ‡ฉ
๐Ÿ’ญ Why this thread?

โ‘ If you have just started learning JavaScript, you might have felt exhausted by seeing so many methods.

โ’ If you are simply going through those methods without knowing their use cases, it's going to be tough for you later.

โ‘ Let's learn use cases.
๐Ÿ“‹ Table of Contents

โ‘ Array.prototype's

โžŠ forEach()
โž‹ map()
โžŒ reduce()
โž every()
โžŽ filter()
โž find()
โž slice()
โž‘ splice()
โž’ push()
โž“ pop()
โžŠโžŠ shift()
โžŠโž‹ unshift()
โžŠโžŒ indexOf()
โžŠโž findIndex()
โžŠโžŽ sort()
Read 25 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 on Twitter!

:(