Skip to main content

How to Count Words and Characters in JavaScript - #103

Published: January 18, 2023 | DevDrawer

Estimated Reading Time
1 minutes
Video Duration
21:48 minutes

In this video, we'll be exploring how to count words and characters in JavaScript. We'll be using the String constructor and the length property to get the word and character count for a string.

This is a really useful technique for understanding how strings work and for debugging purposes. If you're looking to learn more about JavaScript strings, then this is the video for you!

Most if not all developers have used some sort of character counter online to validate SEO, or to just see how many characters a string has. You can do this on your own website or internal tooling. It is simple JavaScript and can have a wide variety of uses throughout your career as a JavaScript developer.

0:00 Intro

00:34 Setup Folder Structure

01:26 Build HTML

05:08 Add Sass / CSS

13:37 Setup Count JS Class

15:28 Count Words Function

16:40 Count Characters Function

17:11 Update Counts Function

19:24 Make It Run on Load

20:03 Make It Run on Text Input

View Project on Github: Get source after the premier

⭐ Join the Discord:

⭐ If you would like to buy me a coffee because I created something that helped you, it would be much appreciated! :

⭐ Join this channel to get access to perks:

⭐ Become a Patreon to show support and get exclusive access to content: