I was playing with JS while I noticed a strange behaviour with backslash \ inserted into a string within an array printed using JSON.stringify(). Of course the backslash is used to escaping special chars, but what happens if we need to put backslash in a string? Just use backslash to escape itself you're thinking, but it doesn't work with JSON.stringify
This should print one backslash
array = ['\\'];
document.write(JSON.stringify(array));
This should print two backslashes
array = ['\\\\'];
document.write(JSON.stringify(array));
Am I missing something? Could be that considered as a bug of JSON.stringify?
array = ['\'];will fail with an unterminated string.."\"would be invalid JSON, since it is an unterminated string. I'm not sure where your confusing comes from.