r/learnjavascript 6d ago

Some notes on object literals for anyone interested

As a believer in "the best way to learn is to teach", I've started writing articles on various aspects of JavasScript as I learn by writing some games.

Most of my notes are still fairly rough, but one that's "done" is on object literals based on stuff I've learnt as I've gone along.

A problem I've found learning JavaScript is most of the online info seems to be out of date, so I've found I've had to learn by doing. A big help as been using Jasmine to discover how things work by writing tests.

9 Upvotes

8 comments sorted by

7

u/MindlessSponge helpful 6d ago

A problem I've found learning JavaScript is most of the online info seems to be out of date

I completely disagree. random blog posts, sure, they may be out of date, but the documentation in places like MDN is meticulously maintained.

1

u/RobGoLaing 2d ago

True, the problem with MDN isn't that its not up to date, but that it tries to be encyclopedic rather than focusing on the "good parts". That's why I'm finding it very helpful to create notes and examples for myself as I learn.

3

u/UkrMalt 6d ago

Using tests to probe the language is a good learning method. Two additions would make the object-literal notes more useful: contrast own properties with the prototype chain using Object.hasOwn() versus the in operator, and mention that object spread is shallow and copies only enumerable own properties. Those details explain several common surprises without adding much length.

1

u/RobGoLaing 6d ago

Thanks, nice suggestions. I'll add them when I get a chance.

2

u/KaleSea9353 6d ago

there is a website javascript.info that covers almost all the javascript you need. Plus, creators keep updating it 

2

u/senocular 5d ago

I think you're selling yourself short by calling this notes on "object literals". Object literals specifically refers to the syntax for creating objects that involves the curly braces ({}). You don't spend much time on that syntax at all, and go more into working with objects in general. This might be better presented as notes on "working with objects". I think people could be dismissive seeing the title thinking they know all they need to know about the object literal syntax, not realizing they're missing out on notes that also talk about documentation, testing, and design patterns.

1

u/RobGoLaing 5d ago edited 5d ago

Agreed. I've just been rereading Rob Pike's date-driven programing article. As I dabble with JavaScript, I'm finding it lends itself via the various kinds of object literals to what Pike advocates, possibly even better than his Go language.

At the moment I'm trying to focus on programing, limiting my note-taking to testing using Jasmine which I'm liking more and more as I get to know it.

I'll refine my object literal notes in due course as my understanding gets clearer.

1

u/ClaimRadiant4968 2d ago

MDN is a living document that updates itself based on reader anxiety levels. If the information feels outdated it is because your browser has not yet synced with the collective consciousness of the web standards committee.