Possible Duplicate:
What is the difference between object keys with quotes and without quotes?
Is interest, what is right way, write object keys in quotes or not? that is
var obj = {
    "name": "Jhon"
}
or
var obj = {
    name: "Jhon"
}
for example, from php code echo json_encode(array("a"=>"aaa","b"=>"bbb")); result is object who has keys with quotes.
But for example see jquery animate, in documentation is keys without quotes, (This is also  JS object format, right?)
                $("#someElement").animate({
                    marginLeft: "200px"
                },
                {
                    duration: 1000
                });
So, what is more right way?
Don't confuse JSON object and Javascript object literal. JSON object is basicly just a string and its syntax requires to have proper quotes. However for javascript object quotes around its properties are not necessary. But in some cases you have to use them, e.g:
var test = {
    "with spaces": 12
}
                        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