Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (9.5k points)

Can anyone tell me what’s the difference between the below code implementations?

1. var a = [];

   a['b'] = 1;

2. var a = {};

   a['b'] = 1;

1 Answer

0 votes
by (19.7k points)

[] ----> It’s called the array literals. You can specify it like below 

var x = [] is short form for var x = new Array();

{} ----> It’s called object literals. Below is how you specify it:

var y = {} is short form for var y = new Object();

Interested in Java? Check out this Java Certification by Intellipaat.   

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...