I found this in a jQuery file:
xxx.css({ 'float' : 'right' });
What do the curly braces do?
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.
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.
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.
In writing, curly brackets or braces are used to indicate that certain words and/or sentences should be looked at as a group.
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.
The curly braces in the code you've shown define an object literal
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With