0

Why can't you access the object's indexes without declaring them? I thought an array has indexes automatically

12th Oct 2016, 10:34 AM
Whitemill
3 Respostas
+ 3
How can you access something that doesn't exist? Edit: looks like you meant initializing instead of declaring. And while you can access an unitialized variable, its value will be just whatever was in memory, ie a garbage value not corresponding to anything.
12th Oct 2016, 11:06 AM
Zen
Zen - avatar
+ 1
That's because, that particular element you are trying to access has a null value. Merely declaring an array doesn't mean that you may already access its elements. you have to initialize its elements first before you can access them.
12th Oct 2016, 3:15 PM
Erwin Mesias
Erwin Mesias - avatar
0
But an array has indexes when it's number of indexes is declared...
12th Oct 2016, 2:55 PM
Whitemill