JS Startup

Challenges, Tips & Tricks & Tutorials

JavaScript Quiz – string length and number length what they return?

JavaScript Quiz – string length and number length what they return?

String Length and Number Length

JavaScript string is a primitive value which have some property and method in which length is an important one because it return the length of string. But what about the javascript number.

Basic Syntax of JavaScript String Length


For more detail about the javascript string length click here.

JavaScript Question

In this javascript quiz, find out string length and number length what they return as string have length property but what about number.

First, we declare a variable number using let keyword and assign an javascript string to it.

let number = 1010;

In the next second step, created another variable name and assign a javascript string to it.

let name = "Ajay";

Finally, we are checking the value of both the variable for their length property.


Any idea, what should be the output of above code statement.

JavaScript Quiz Test

Here is the full javascript code snippet for you to solve.

let number = 1010;

let name = "Ajay";

// output => ? ?

// output => ? ?

// Made with ❤️, by @jsstartup

Answer – 4, undefined

Click To Run Code


Now, you know the answer is 4, undefined. But why, doesn’t it should give 4, 4 because both have length 4. Let me explain.

InShort, javascript number does not have length property. So when you try to access the property which actually not exist then it leads to undefined.

But javascript string have the length property which obviously give the length of the string.

At last, That’s why we get an answer “4, undefined”

Let me know in the comment section, what you think about it.

I hope you understand the concept and logic behind it.

But wait, i have something more for you –

Check out our other javascript quiz – 

  1. JS Quiz – for loop iterate array in two ways
  2. JS Quiz – array element duplicate count with for loop
  3. JavaScript Quiz – isArray method and typeof intend is different
  4. JavaScript Quiz – does replace really work on replaced string


To participate in our javascript quiz or challenges, tutorial, tips & tricks make sure to join our jsstartup newsletter. So, you can able to participate in our daily challenges & learn the javascript concept.

And last but not the least, don’t forget to like, comment and share. It gives us a morale boost to remain to continue. Also, join our Facebook Page

If you have any questions, please feel free to ask me in the comment section and also let me know if you have any suggestions. As suggestions are always welcome.

Leave a Reply

Your email address will not be published.

Back to top
Share via
Copy link
Powered by Social Snap