Training day 15 - JavaScript Basic to Beginners

Heloo people!!

Following notes:

Objects

Factory function

function createCircle(radius) { return { radius: radius, draw: function() { console.log(‘draw’); } } }

if key and value are same, we can directly use value - like this:

function createCircle(radius) { return { radius, draw: function() { console.log(‘draw’); } } }

We can even simplify the draw method

```function createCircle(radius) { return { radius, draw() { console.log(‘draw’); } } }


- Camel Notation: oneTwoThreeFour
- Pascal Notation: OneTwoThreeFour

- Constructor Function

function Circle(radius) { this.radius = radius, this.draw = function() { console.log(‘draw’); } }

const circle = new Circle(1);


- Remove property from object

const circle = { radius: 1 };

circle.color = “yellow”; delete circle.color; ```

Here we see, it seems like we modified the object but we can add or remove properties but cannot reassign the object.

Byeee!