freeCodeCamp/guide/english/certifications/javascript-algorithms-and-d.../basic-javascript/find-the-length-of-a-string/index.md

13 lines
508 B
Markdown
Raw Normal View History

2018-10-12 19:37:13 +00:00
---
title: Find the Length of a String
---
## Find the Length of a String
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
Strings have an <strong>attribute</strong> (feature) called 'length'. All you have to do is tag it after the string / variable.
var str1 = "Hello";
var length1 = str1.length; // This returns 5
var length2 = " Camper".length; // This returns 7 because the space is counted as one character.