+ 2

I have a question...

Why in javascript if I declare object within object it gives an error, but if I first declare object and then put it inside other object it works fine. for example: //doesn't work var obj1; var obj2; var database={ obj1={}, obj2={} } //works fine var obj1={} var obj2={} var database={ obj1, obj2 }

16th Jun 2018, 2:42 PM
Prathamesh Sawant
Prathamesh Sawant - avatar
5 Answers
+ 4
In object , values are stored as key value pair and they are seperated using colon.
16th Jun 2018, 4:16 PM
Meet Mehta
Meet Mehta - avatar
+ 2
yep, you have to do it with the colon to work in objects
16th Jun 2018, 4:46 PM
Haon1919
Haon1919 - avatar
+ 1
youd want to do something like this... https://code.sololearn.com/WbjAeFY4OeLO/?ref=app
16th Jun 2018, 2:48 PM
Haon1919
Haon1919 - avatar
+ 1
Ok thanks â˜ș
17th Jun 2018, 3:36 AM
Prathamesh Sawant
Prathamesh Sawant - avatar
0
Now it is working fine. But why didn't it work for "=" sign. Is it because it is inside an object?
16th Jun 2018, 3:33 PM
Prathamesh Sawant
Prathamesh Sawant - avatar