Both are valid javascript, but only one is valid json. However many json parsers are leaniant in what they accept.
var moo = { foo: "bar" } // this is javascript, not json. JSON.stringify(moo) should give '{ "foo": "bar" }' // this is json. So if you are passing json to something, it needs to be quoted, if you are providing a javascript snippet you can do whatever