JSON.stringify(value)
will convert a JavaScript value to JSON string. JSON.parse(value)
will convert a valid JSON string into a JavaScript value (object, array or other JSON-available primitive).
Why would you take a JavaScript value and move it through JSON ? Means take a value then stringify it and then parse it back. It serves no purpose to my knowledge and just wastes machine resources.
I'm asking this is because I've come across this function:
function ser(value) {
return value == null ? null : JSON.parse(JSON.stringify(value))
}
it's found in crow-tech.js in sandbox of Chapter 11 of book Eloquent JavaScript by Marijn Heverbeke and I'm wondering why would he wanna do that!