# Symbols

* 6th primitive in javascript ( number, boolean, string, null, undefined )
* Use to created unique identifier
* or basically used to avoid conflict of variable names

```
let x= Symbol('hemant');
```

```javascript
// it may happen
let classRoom = {
    'hemant': {grade: 30, gendar: 'Male'},
    'vinita': {grade: 30, gendar: 'Female'},
    'vinita': {grade: 30, gendar: 'Female'}
}

// To avoid above
let classRoom = {
    [Symbole('hemant')]: {grade: 30, gendar: 'Male'},
    [Symbole('vinita')]: {grade: 30, gendar: 'Female'},
    [Symbole('vinita')]: {grade: 30, gendar: 'Female'}
}

console.log(classRoom); // no console output
```

## Access Symbol

```javascript
let classRoom = {
    [Symbol('hemant')]: {grade: 30, gendar: 'Male'},
    [Symbol('vinita')]: {grade: 30, gendar: 'Female'},
    [Symbol('vinita')]: {grade: 30, gendar: 'Female'}
};


for(val in classRoom){
    console.log(val)
}

var rooms = Object.getOwnPropertySymbols(classRoom);
let data = rooms.map(item => classRoom[item]);
console.log(rooms); // [Symbol(hemant), Symbol(vinita), Symbol(vinita)]
console.log(data); 
// [{"grade":30,"gendar":"Male"},{"grade":30,"gendar":"Female"},{"grade":30,"gendar":"Female"}]
```
