Vradhit
Vradhit3y ago

Vradhit – 11-46 Aug 2

What is the meaning of const variable =[0] ? In js
9 Replies
ScriptyChris
ScriptyChris3y ago
variable is assigned with an array containing 0 (zero) digit
Vradhit
VradhitOP3y ago
Ok we can also specify using fill method also right?
ScriptyChris
ScriptyChris3y ago
Yes, but in this example using .fill() method seems like an overkill
Vradhit
VradhitOP3y ago
Ok thanks for the info What is the difference of declaring empty array over this 0?
ScriptyChris
ScriptyChris3y ago
I don't understand your question 😐 [] is an empty array and [0] is an array with zero inside
Vradhit
VradhitOP3y ago
Ok so initialising with 0 and then pushing the new element will it over rite correct that 0 inside it
ScriptyChris
ScriptyChris3y 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]
Vradhit
VradhitOP3y ago
Oh ok thanks for understanding me this concept
reactibot
reactibot3y ago
This thread hasn’t had any activity in 12 hours, so it’s now locked. Threads are closed automatically after 12 hours. If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/1003992220032040960