How do you get the length of a string in Javascript?


#1


https://www.codecademy.com/courses/getting-started-v2/4/2?curriculum_id=506324b3a7dffd00020bf661#


This is what I typed in: console.log(myCountry.len());
This is the error message TypeError: myCountry.len is not a function

// Declare a variable on line 3 called
// myCountry and give it a string value.
myCountry= "Maybe";

// Use console.log to print out the length of the variable myCountry.
console.log(myCountry.len());

// Use console.log to print out the first three letters of myCountry.
console.log(myCountry.substring(0,3));


#2

To get the length of a string you type:

(stringName.length);

#3

@12mmb, remember when we learned about asking for the length of a string back in exercise 2. Discover the length?

@funct1on, your answer would be nicer without those ( ).


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.