Vradhit – 11-46 Aug 2

What is the meaning of const variable =[0] ? In js
S
ScriptyChris625d ago
variable is assigned with an array containing 0 (zero) digit
V
Vradhit625d ago
Ok we can also specify using fill method also right?
S
ScriptyChris625d ago
Yes, but in this example using .fill() method seems like an overkill
V
Vradhit625d ago
Ok thanks for the info What is the difference of declaring empty array over this 0?
S
ScriptyChris625d ago
I don't understand your question 😐 [] is an empty array and [0] is an array with zero inside
V
Vradhit625d ago
Ok so initialising with 0 and then pushing the new element will it over rite correct that 0 inside it
S
ScriptyChris625d ago
No, using .push() doesn't override anything in an array - it adds new value to the end of that array So if you used .push(2) to your variable then you would have array looking like this [0, 2]
V
Vradhit625d ago
Oh ok thanks for understanding me this concept
UU
Unknown User625d ago