1

Why when I try this block of code:

var str = "1234";
alert(str.toString().lenght);

it alerts me 'undefined' ?

4 Answers 4

7

You misspelled length. It's "length":

str.toString().length

You don't actually need the toString() call here, though. "1234" is already a string, so str.length works as well.

Sign up to request clarification or add additional context in comments.

2 Comments

Ah. dyslexic moments are always such fun. i always type "ponit" instead of "point" for some reason. usually I catch them...
I edited, but my post initially read "You mispelled". Oops.
1

correct your spelling...

alert(str.toString().lengTH);

Andrew

Comments

1

You have a spelling mistake in that code. It's length not lenght.

But aside from that, there's no need to call toString(). str.length is fine.

Comments

0

Just a typo: it's .length ;)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.