+ 2

Why zero ?

That's a code i sound of FreeCodeCamp to print out the length of a string, but why did they assign the value of "firstNameLength " to zero ? here's the code: var firstNameLength = 0; var firstName = "Ada"; firstNameLength = firstName.length;

24th Jan 2020, 1:32 PM
Marina Khamis
Marina Khamis  - avatar
4 Respostas
+ 2
Normally you dont have to initialize variabiles in Java Script. But could be a good practice derived from languages like Java.
24th Jan 2020, 1:43 PM
Mihai Apostol
Mihai Apostol - avatar
+ 1
That's hard to say without the context. Can you upload more of the code and link it here?
24th Jan 2020, 1:41 PM
HonFu
HonFu - avatar