Swapna Kumar Panda ๎จ€ Profile picture
Mar 13 โ€ข 25 tweets โ€ข 8 min read
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()
โ’ String.prototype's

โžŠโž toLowerCase()
โžŠโž toUpperCase()
โžŠโž‘ substring()
โžŠโž’ indexOf()
20. charAt()
โž‹โžŠ trim()

โ‘ Math's

โž‹โž‹ floor()
โž‹โžŒ random()

โ’ Global

โž‹โž setTimeout()
โž‹โžŽ setInterval()
โžŠ Array.prototype.forEach()

โ Use Case

โœ” To iterate through each element in the array
โœ” Perform a task on each element

โœ˜ Not suitable if task is supposed to return some value

โœฉโœฉ forEach() is also available in Set.prototype and Map.prototype
โž‹ Array.prototype. map()

โ Use Case

โœ” To iterate through each element in the array
โœ” Perform a task on each element which returns a value
โœ” Returns a new array with all returned values

โœ˜ Not suitable if task doesn't return any value
โžŒ Array.prototype.reduce()

โ Use Case

โœ” To iterate through each element in the array
โœ” Perform a task on each element which accumulates the previous returned value with current element to return a new value

โ Example

โž€ Sum of all items
โž Max of all items
โž Array.prototype.every()

โ Use Case

โœ” To iterate through elements in the array until a certain condition is not met
โœ” The task performed on each element must return a boolean value

โœ˜ Stops iterating when condition is not met. Hence, it's not suitable for skipping.
โžŽ Array.prototype.filter()
โž Array.prototype.find()

โ Use Case

โœ” To find element(s) which match a criteria
โœ” Use find() to find the first matched element
โœ” Use filter() to find all matched elements

โœฉโœฉ filter() returns a new array of matched elements
โž Array.prototype.slice()

โ Use Case

โœ” To fetch a sub-array from a larger array

โœฉโœฉ slice() returns a new array, doesn't modify the existing array
โž‘ Array.prototype.splice()

โ Use Case

โœ” To replace a portion of the array with new elements

โœฉโœฉ splice() modifies the existing array
Array.prototype's
โž’ push()
โž“ pop()
โžŠโžŠ shift()
โžŠโž‹ unshift()

โ Use Case

โœ” Use push() and pop() to insert/remove elements from the end
โœ” Use shift() and unshift() to insert/remove elements from the start

โœฉโœฉ These methods modify the existing array
Array.prototype's
โžŠโžŒ indexOf()
โžŠโž findIndex()

โ Use Case

โœ” To find index of the first matched element
โœ” indexOf() does exact match (===)
โœ” findIndex() allows for custom match
โžŠโžŽ Array.prototype.sort()

โ Use Case

โœ” To sort all elements of an array in some order
โœ” Provide a comparator to define custom order
โœ” By default sorting order is lexical

โœฉโœฉ This method modifies the existing array
String.prototype's
โžŠโž toLowerCase()
โžŠโž toUpperCase()

โ Use Case

โœ” To convert entire string to lowercase alphabets, use toLowerCase()
โœ” To convert entire string to uppercase alphabets, use toLowerCase()

โœฉโœฉ These methods returns a new string
โžŠโž‘ String.prototype.substring()

โ Use Case

โœ” To fetch a part of the string between 2 indexes

โœฉโœฉ substring() returns a new string
โžŠโž’ String.prototype.indexOf()

โ Use Case

โœ” To find the very first occurrence of a "substring" in the original string
โœ” We can also mention from which index the occurrence should be checked
20. String.prototype.charAt()

โ Use Case

โœ” To fetch the character at a specific position of a string.
โœ” The character fetched is in UTF-16 and returned as a string
โž‹โžŠ String.prototype.trim()

โ Use Case

โœ” To remove whitespace from both ends of a string

โœฉโœฉ trim() returns a new string
โž‹โž‹ Math.floor()

โ Use Case

โœ” To get the largest integer less than or, equals to the given number
โž‹โžŒ Math.random()

โ Use Case

โœ” To get a floating point pseudo random number in the range of 0 to less than 1
โœ” It can be multiplied by any number to make a random number being generated in the range of 0 to less than that number
โž‹โž setTimeout()

โ Use Case

โœ” To execute a function or, piece of code after a timer expires
โœ” The code is executed only for once.

โœ˜ It is an asynchronous function. It shouldn't be used where pausing of execution is intended.
โž‹โžŽ setInterval()

โ Use Case

โœ” To execute a function or, piece of code repeatedly with a fix time delay

โœ˜ The code is ensured to be executed each time after the time delay. But not "exactly" after the time delay.

โœฉโœฉ Cancel further execution using clearInterval()
๐Ÿ’ญ Feedbacks

โœง I have picked 25 out of 100s of methods available. My focus was to show you a "learning method" which you may apply wherever you wish.

โœง Share your feedbacks on these. It would definitely help me to share better contents with you.
End of ๐Ÿงต

If you are a new learner or, someone who finds difficulties in learning JavaScript, you have reached to right person here.

You may like to go through "JavaScript" & "JavaScript Infographics" moments to see what I share regularly.

To never miss any, 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 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 12
๐Ÿ’Ž JavaScript Cheat Sheet : Math Object

Find Complete Reference of
โ 8 Constants
โ 35 Functions

โœง Link to High Resolution image in the next tweet JavaScript Math Object  1. Constants  a. Math.E  b. Math.LN2
๐Ÿ™ High Resolution Image

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

โฌ“ Direct Link:
github.com/swapnakpanda/Iโ€ฆ
๐Ÿšฅ Disclaimer

โฌ” I have compiled these information with all sincerity. But in case you find any omissions or, wrong representations, ๐Ÿ’ฌ me.

โฌ• Share your feedbacks if you see any area of improvement for me. Feedbacks are highly appreciated.
Read 4 tweets
Mar 11
Let's redefine the "undefined". Can we do it in JavaScript?

โ‡ฉ
โžŠ What is "undefined"?

โ‘ "undefined" is a variable in the global scope. The value of "undefined" is the primitive value "undefined"

โ’ When a variable is declared but not assigned any value, value of global variable "undefined" is assigned to it implicitly.
โž‹ "undefined" is not a reserved keyword

โ‘ It means you can declare a variable named "undefined".

โ’ So, what will happen if you declare a variable called "undefined" and assign some other value to it?

Let's explore.
Read 7 tweets
Mar 10
๐ŸŸฆ All inline & block-level elements in HTML / CSS

Check inside the ๐Ÿงต for

โœง Interesting details about inline & block-level
โœง Link to high resolution image

โ‡ฉ HTML elements can be categorized as either "block-level
๐Ÿ“‹ Table of Contents

โžŠ Introduction
โž‹ inline-level
โžŒ block-level
โž Changing Element Level
โžŽ List of inline-level elements
โž List of block-level elements
โž Link to High Resolution Image
๐Ÿšฅ Disclaimer

โ‘ I have compiled these information with all sincerity. But in case you find any omissions or, wrong representations, ๐Ÿ’ฌ me.

โ’ If you have any suggestions or, feedbacks, share those with me. I am eager to hear from you.
Read 18 tweets
Mar 9
๐Ÿ™ Should we use Semantic HTML?

โœ˜ <div> โžœ <header> โœ“
โœ˜ <div> โžœ <nav> โœ“
โœ˜ <div> โžœ <section> โœ“
โœ˜ <div> โžœ <article> โœ“
โœ˜ <div> โžœ <aside> โœ“
โœ˜ <div> โžœ <main> โœ“
โœ˜ <div> โžœ <summary> โœ“
โœ˜ <div> โžœ <footer> โœ“

โ‡ฉ
We will discuss about

โžŠ What is Semantic HTML?
โž‹ Examples of Semantic Elements
โžŒ Benefits of using Semantic HTML
โžŒ.โž€ Improve site's SEO positioning
โžŒ.โž Help your site more accessible
โžŒ.โž‚ Closer to natural language, easier to maintain
โž Should we not use "div"?
โžŠ What is Semantic HTML?

โ Semantic HTML adds essential meaning to the web page rather than just presentation.

โ This lets web browsers, search engines, screen readers, RSS readers, and ultimately users understand it in a better way.
Read 14 tweets
Mar 8
Memorise JavaScript Array Methods in 11 Steps

โ‡ฉ
๐Ÿ“‹ TOC

โžŠ Static Methods
โž‹ Accepts -ve Index
โžŒ Returns Boolean
โž Returns Index
โžŽ Returns new Array
โž Modifies Existing Array
โž Iterates through entire Array
โž‘ Iterates Partially
โž’ Checks Elements "as it is"
โž“ Checks Elements custom way
โžŠโžŠ Accepts a callback
โžŠ Static Methods

โ of()
โ from()
โ isArray()
Read 15 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!

:(