Could you guys please explain the difference between the two following variables?
var test = {};
var test2 = [];
Are they not both declaring an array variable? If not, when to use which?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The first creates an object (empty object with no properties at all).
The second creates an empty array.
Let’s take an example of manipulating an object:
you could also dynamically extend an existing empty object and add properties to it:
and an array:
or to add elements to an array: