I've been experimenting with JSON recently and came across something I don't quite understand. Here is an example of some code I used:
var str = "{'name':'vvv'}";
var cjson = eval ("(" + str + ")");
alert(cjson.name);
That code works well, but when I tried this piece of code:
var str = "{'name':"+'vvv'+"}";
var cjson = eval ("(" + str + ")");
alert(cjson.name);
It didn't work, and I received the following error in Firebug: ReferenceError: vvv is not defined.
What's causing it to fail in the second example? Shouldn't 'str' be a valid string in both cases?