Skip to content

Instantly share code, notes, and snippets.

@tomatohammado
Created November 27, 2019 19:15
Show Gist options
  • Save tomatohammado/49aadd0150c452ff48f45fc4812d7b9a to your computer and use it in GitHub Desktop.
Save tomatohammado/49aadd0150c452ff48f45fc4812d7b9a to your computer and use it in GitHub Desktop.
Native Object vs JSON examle
const testObj = {
name: "Hammad",
age: 30,
favoriteAnime: [
"Cowboy Bebop",
"Dragon Ball",
"Death Note",
"Samurai Champloo"
],
holla: () => console.log("hollaaaaaaa")
};
const jsonTestObj = JSON.stringify(testObj);
const parsedJson = JSON.parse(jsonTestObj);
/** Testing */
console.log(testObj.name);
console.log(testObj.favoriteAnime[0]);
console.log(testObj.holla());
console.log(jsonTestObj);
console.log(jsonTestObj.name); // doesn't work!
console.log(parsedJson.name);
console.log(parsedJson.favoriteAnime[0]);
console.log(parsedJson.holla()); // doesn't work!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment