{"comment":{"url":"https://api.github.com/repos/desinas/javascript-30-works/comments/31296550","html_url":"https://github.com/desinas/javascript-30-works/commit/9e394e1eb82b2d8d92a85d4c0ecbeb1c1beb62b2#commitcomment-31296550","id":31296550,"node_id":"MDEzOkNvbW1pdENvbW1lbnQzMTI5NjU1MA==","user":{"login":"desinas","id":4653451,"node_id":"MDQ6VXNlcjQ2NTM0NTE=","avatar_url":"https://avatars2.githubusercontent.com/u/4653451?v=4","gravatar_id":"","url":"https://api.github.com/users/desinas","html_url":"https://github.com/desinas","followers_url":"https://api.github.com/users/desinas/followers","following_url":"https://api.github.com/users/desinas/following{/other_user}","gists_url":"https://api.github.com/users/desinas/gists{/gist_id}","starred_url":"https://api.github.com/users/desinas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/desinas/subscriptions","organizations_url":"https://api.github.com/users/desinas/orgs","repos_url":"https://api.github.com/users/desinas/repos","events_url":"https://api.github.com/users/desinas/events{/privacy}","received_events_url":"https://api.github.com/users/desinas/received_events","type":"User","site_admin":false},"position":null,"line":null,"path":null,"commit_id":"9e394e1eb82b2d8d92a85d4c0ecbeb1c1beb62b2","created_at":"2018-11-14T12:12:40Z","updated_at":"2018-11-14T12:12:40Z","author_association":"OWNER","body":"Manipulating by Value\r\n\r\nPrimitive types are manipulated by value. The following types are considered primitive types in JavaScript:\r\n\r\n    String\r\n    Number\r\n    Boolean\r\n    Null\r\n    Undefined\r\n\r\nThis means that if we define a variable as a primitive type, and then define another variable as the previously defined variable, the second variable will copy the current value of the first variable. Any changes to the first variable will not effect the second, and vice versa.\r\n\r\nExample:\r\n\r\n    let me = \"Nitish\"\r\n    let me2 = me\r\n    console.log(me === me2) // true\r\n\r\n    me2 = \"Bob Dylan\"\r\n    console.log(me === me2, me, me2) // false, \"Nitish\", \"Bob Dylan\"; I'm not Bob Dylan\r\n\r\n    me = \"Not Nitish\"\r\n    console.log(me === me2, me, me2) // false, \"Not Nitish\", \"Bob Dylan\"\r\n\r\nManipulating by Reference\r\n\r\nObject types are manipulated by reference. If it's not a primitive type, it's always an object. If we're being really technical, almost everything can be an object in JavaScript, even primitive types (excluding null and undefined), but let's try not to get hung up on technicalities.\r\n\r\nA small list of object types in JavaScript:\r\n\r\n    Object\r\n    Function\r\n    Array\r\n    Set\r\n\r\nLet's say we declare a variable and define it as an object, then declare another variable and define it as the first variable:\r\n\r\n    const me = {name: \"Nitish\", age: 26}\r\n    const me2 = me\r\n    console.log(me === me2) // true\r\n\r\nIf we update the property of the object by calling on either variable, both variables will reflect that change.\r\n\r\n    me.name = \"Not Nitish\"\r\n    console.log(me === me2) // true\r\n    console.log(me2) // { name: 'Not Nitish', age: 26 }\r\n\r\nThis is because me2 does not copy me; it contains a reference to the object defined in const me. Any changes applied directly to the object will have an effect on all variables referencing that particular object. So what could we do if we wanted to make a copy of the original object so as not to manipulate the root source of data?\r\n\r\n    const me3 = Object.assign({}, me) // create a new object\r\n    console.log(me3) // {name: 'Not Nitish', age: 26}\r\n    console.log(me === me3) // false! It's a new object instance!\r\n    console.log(me.name === me3.name) // true! The property values are the same!\r\n    me3.name = \"Devin\"\r\n    console.log(`${me.name}, ${me3.name}`) // 'Not Nitish, Devin'\r\n\r\nWe have effectively copied the first object and can modify our copy without manipulating the original.\r\n\r\nWARNING: If we copy an object containing objects, we are only copying the first level. Anything deeper than that will still be a reference."}}
{"actor":{"display_login":"desinas"}}