Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do curly braces in JavaScript mean?

I found this in a jQuery file:

xxx.css({ 'float' : 'right' }); 

What do the curly braces do?

like image 278
Mouse Hello Avatar asked Mar 14 '12 09:03

Mouse Hello


People also ask

What does {} mean in JavaScript?

google doesn't have value (undefined, null) then use {} . It is a way of assigning a default value to a variable in JavaScript. Follow this answer to receive notifications.

What does empty curly braces mean in JavaScript?

It means the variable is a dictionary that stores key value pairs. The subscript or the value within the [] brackets is the key and the value on the right side is the value.

Does JavaScript need curly braces?

Yes, it works, but only up to a single line just after an 'if' or 'else' statement. If multiple lines are required to be used then curly braces are necessary.

What are {} used for?

In writing, curly brackets or braces are used to indicate that certain words and/or sentences should be looked at as a group.


2 Answers

In your case it is an object passed to your css function.

myObj={} // a blank object 

Here you can use this too

myObj={'float' : 'right'} xxx.css(myObj); 

Here is another example of object

var myObj={     'varOne':'One',     'methodOne':function(){ alert('methodOne has been called!')}         } myObj.methodOne();​ // It will alert 'methodOne has been called!' 

A fiddle is here.

like image 134
The Alpha Avatar answered Sep 21 '22 16:09

The Alpha


The curly braces in the code you've shown define an object literal

like image 22
Rafael Avatar answered Sep 21 '22 16:09

Rafael