Coding / Programming Videos

Post your favorite coding videos and share them with others!

Javascript String Length: How to determine the size of a string

In this tutorial, we’ll take a look at the JavaScript String Length property and how you can use this to determine the size of a string.

Don’t forget to subscribe to the Junior Developer Central channel for more videos and tutorials!

It’s a very common thing to do but to use the JavaScript string length property is luckily really simple.

In the tutorial, you’ll learn how to use the .length property to find out the length of a string but we’ll also look at some common scenarios that you might want to use the length property for.

Checking for null / falsy JavaScript string lengths – This is something that is quite common, you might have an array of strings that you want to check whether or not they are empty i.e. remove any blank strings from an array. Whilst a blank string is considered falsy, you might want to check the additional length property to make your code a bit more readable (or if you have a specific case to allow null or undefined values).

Checking variables with a JavaScript string length comparison – If you have two strings that you want to compare the length of then you’ll need compare their lengths by accessing the length property of both variables.

The Javascript string length undefined Problem – If you get an undefined result when trying to get a string’s length in JavaScript then chances are you don’t actually have a string. In the tutorial i’ll talk you through how to check that you’re actually working with a string and to convert it to one if necessary.

Javascript String Length Validation on Input fields – The final example we’ll look at is how to validate an input field’s length with JavaScript by checking the length property of the string entered into the input box.

Other videos in the JavaScript Snippets series:
Find the largest number in an array JavaScript Tutorial:
How to find the longest word in a String with JavaScript:
How to reverse a String in JavaScript Tutorial:
Javascript String Length: How to determine the size of a string:
JavaScript join method: How to merge arrays into one value:
JavaScript How To Remove An Item From Array Tutorial:
Javascript How To Convert String To Number Tutorial:
JavaScript Create HTML Element: How to dynamically add tags to your pages:
JavaScript String Contains: How to check a string exists in another:
Link JavaScript to HTML: How to run your JavaScript code in the browser:
JavaScript Copy Array: How to make an exact copy of an array in JavaScript:
JavaScript Capitalize First Letter: How to make strings and arrays sentence case:
Javascript Print To Console Tutorial: Different ways to output data to the console:


Leave a Reply

Please Login to comment
Notify of
Translate »