Don't Look! I'm changing!

URL Copied

Audio Version

Links:

I have a bunch of notes on random things I catalog here.

The article contents may stray from the page title.

I can't speak to the veracity nor fidelity of it all but I'm sharing em!

A lot if these pages are timelines or help put things into context for me.

Contact [email protected] should you have any revisions, questions, comments, or concerns!

https://blog.jetbrains.com/webstorm/2024/10/javascript-best-practices-2024/?ref=dailydev

const obj = { name: 'Alice' }; const hiddenKey = Symbol('hidden'); obj[hiddenKey] = 'Secret Value'; console.log(Object.keys(obj)); // ['name'] (Symbol keys won't appear) console.log(Object.getOwnPropertySymbols(obj)); // [Symbol(hidden)] (accessible only if specifically retrieved)

Why it matters: Map is a more flexible and predictable way of associating values with any kind of key, whether primitive or non-primitive. It preserves the type and order of keys, unlike plain objects, which convert keys to strings. const map = new Map(); const key = { id: 1 }; // Using a non-primitive object as a key in a Map map.set(key, 'value'); console.log(map.get(key)); // 'value'

Why it matters: Arrow functions enhance readability by removing boilerplate code, making callback functions and inline expressions much more concise. In addition, they are particularly valuable when working with classes or event handlers, as they automatically bind this to the surrounding lexical scope. This avoids common bugs related to this in traditional function expressions, especially in asynchronous or callback-heavy code.

Advice: When you really need private fields in classes, JavaScript now has real private fields using the # syntax. This is an official language feature that enforces true privacy.

class Person { #name constructor(name) { this.#name = name; } getName() { return this.#name } } const p = new Person('A'); console.log(p.getName()); // 'A' Why it matters: Using real private fields ensures that the data is truly encapsulated, preventing accidental or malicious access from outside the class. The underscore convention only provides a visual cue and can easily be misused, while # private fields guarantee privacy by design. This results in more robust and maintainable code.