Imagine having something like this:
var a = '["\t"]'
When you use:
eval('var result = ' + a)
Everything runs smoothly. However, if you try:
var result = JSON.parse(a)
You'll encounter an error: Unexpected token.
The same issue arises with \b and \f: they work with eval but fail with JSON.parse. Why is that? Shouldn't the parser handle "\t" in a consistent manner?
Additionally, both eval and JSON.parse will fail with \n (as expected), but they also both fail with \r. Why does this happen?
There seems to be some confusion here, so could someone explain what's happening? It would be helpful to understand how the parser behaves in these two scenarios.