codegurukool.com · Free coding tutorials & online compiler

Home › JavaScript Tutorial › JS advanced objects

JS advanced objects

Destructuring, spread, getters.

Destructuring unpacks values. Spread copies objects. Object.entries lists pairs, getters compute values and Object.freeze locks an object.

Example code

<pre id='o'></pre>
<script>
const p={first:'Ada',last:'Lovelace',get full(){return this.first+' '+this.last}};
const {first,...rest}=p;
const q={...p,age:36};Object.freeze(q);
o.textContent=[first,Object.keys(rest),p.full,Object.entries(q).length,Object.isFrozen(q)].join('\n');
</script>

Run this code in the online editor

← JS advanced functionsJS asynchronous →