Tuesday, January 21, 2025
HomeJavaScriptCover object properties with JavaScript symbols

Cover object properties with JavaScript symbols


Printed at

Up to date at

Studying time
1min

This publish is a part of my At this time I realized collection through which I share all my net improvement learnings.

I’ve simply learn Exploring JavaScript Symbols, and it is fairly good. It features a tiny JavaScript nugget that I wasn’t very conscious of.

JS symbols are an underrated language function that I in all probability ought to use for extra issues. And not to mention the properly nerdy well-known symbols that provide help to to actually perceive how JavaScript works underneath the hood.

Considered one of these image use instances is hiding properties in a great outdated JavaScript objects.

const lastTouched = Image('lastTouched');

const file = {
  title: 'schnitzel'
  
  
  [lastTouched]: 'proper now',
};


console.log(file);              
console.log(file[lastTouched]); 


Object.keys(file);                          
Object.entries(file);                       
Object.values(file);                        
JSON.stringify(file);                       
for (let key in file) { console.log(key); } 

An emblem property will not seem in Object.keys and associates, might be ignored in JSON.stringify and is safely hidden in for-in loops. Fairly good!

If you happen to loved this text…

Be a part of 5.5k readers and study one thing new each week with Net Weekly.

Web Weekly — Your friendly Web Dev newsletter

Stefan standing in the park in front of a green background

Associated Subjects

Associated Articles

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments