{"size": 2305, "ext": "js", "max_stars_repo_path": "index.js", "max_stars_repo_name": "GlenTinashe/JavaScriptOOP", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "index.js", "max_issues_repo_name": "GlenTinashe/JavaScriptOOP", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "index.js", "max_forks_repo_name": "GlenTinashe/JavaScriptOOP", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 24.5212765957, "max_line_length": 155, "alphanum_fraction": 0.7010845987}
//factory function
function createCircle(radius ){
    return  {
        radius,
        draw: function(){
            console.log('draw');
        }
    };
}
const circle = createCircle(2);

// Constructor function
function Circle(radius){
    this.radius = radius;
    this.draw = function () {
        console.log('draw');
    }
}

//new operator creates  a new object then sets this to the object and then returns the object from the function
const anotherCircle = new Circle(1);

 //JS allows adding of properties on the fly
 anotherCircle.location = {x:1}
 // this statement aboove is exactly the same as the one below
 circle['location']={x:1}

 //nbracket notation is particularly useful for when dynamically accessing a property name or the property name has special characters like centre-location

 const propertyName = 'location';
 circle[propertyName]= {x:1}

 // delete operator to dynamically delete a property
delete circle.location;
delete circle[location];

 console.log('another circle', anotherCircle);

//value vs reference types

let x = 10;
let y = x;

x= 20;
//x = 20
console.log(x);
//y = 10 because the values are independent of each other
console.log(y);

let a = {value: 10};
let b =a;

a.value = 20;
// a = 20
console.log(a);
// b = 20 because an object is not stored in the variable. the address of the morty location of the object is stored in the variable 
console.log(b);

// primitives are copied by value and objects are copied by their reference e.g

let number = 10;
function increase(number){
    //number = 11 only within this function
    number++;
}
increase(number);
// number = 10 since its copied by value
console.log(number);

let number2 = {value: 20};
function increase(number2){
    number2.value++;
}
increase(number2);
// number = 21 since object is copied by value
console.log(number2);

//iteration over objects using for in
//you can use bracket notation to access the value of properties and methods of the objects


for (let key in circle){
    //to display only properties use the typeof operator
    if(typeof circle[key]!=='function')
    console.log('key',key, circle[key]);
}
const keys = Object.keys(circle)

console.log('keys', keys);

//find if an object has a property or method

if ('radius' in circle)
    console.log('circle has radius');