Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use of {} in JavaScript?

Tags:

javascript

Very simple question but I'm quite new to JS and this is not easy to search.

If I see a line like this:

var colours = {}, r, g, b;

I get that it's just a declaration for 3 vars, but what does the {} bit mean? I can't see anywhere that gives me an idea as to what this is declaring?

Thanks!

like image 633
FBryant87 Avatar asked Dec 05 '22 16:12

FBryant87


2 Answers

It declares new object and equivalent to new Object();

like image 191
antyrat Avatar answered Feb 15 '23 14:02

antyrat


 var colours = {}, r, g, b;

This declares 4 variables which is the same as

   var colors = {}; // this is an empty object like, var colors = new Object();
   var r; // undefined
   var g; // undefined
   var b; // undefined
like image 42
kamui Avatar answered Feb 15 '23 15:02

kamui