JavaScript Algorithms and Data Structures Basic Java script

My question is I’m wondering why we put var lastNameLength = 0, like why is that equal to 0?

Your code so far

// Setup
var lastNameLength = 0;
var lastName = "Lovelace";

// Only change code below this line

lastNameLength = lastName.length;

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36.

Challenge: Find the Length of a String

Link to the challenge:

You don’t have to, but you normally want to assign some value to a variable so the value of a variable won’t be undefined. A natural default value for lastNameLength is 0.

1 Like

Oh makes sense, thank you!

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