Objects: terminology

Hello.

In some of the challenges I’m getting thrown off track by what an object’s property means (most recently on: https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/profile-lookup/).

In the following:

const myObject = {
     firstName = "Bill"
}
  1. Is firstName the key, "Bill" the value, and firstName="Bill" the property?

  2. Or is firstName the property - property just being another name for key?

Some of the challenges suggest 1) is correct, some that 2) is correct.

Can any one clarify this for me?

:slight_smile:

1 Like

If you are creating an object you need to use a colon

const myObject = {
     firstName: "Bill"
}

You can call firstName key, and "Bill" value,

and firstName: "Bill" could be the property but I may be wrong with this

1 Like

Yes, how silly of me, thanks for the correction:

firstName : "Bill" not firstName = "Bill" !

Still looking for a definitive answer to my question - as I mentioned, in some challenges the key and the value seem to be referred to as the property, in others (see the link) key and property seem to be interchangeable terms.

1 Like

I just googled it to give a definite answer, I imagine you didn’t find a source you liked - the MDN can work as a source!

2 Likes

a property is an association between a name (or key) and a value

That nails it - thanks :slight_smile:

1 Like

I think part of the confusion is the intersection between:

  1. other people not knowing the answer so they use what they do know
  2. different concepts with similar names in different contexts
  3. similar concepts with different names in different contexts
  4. the natural evolution of language because of these factors (along with some other factors that are less relevant)

I mention this, because there may be one correct answer according to specifications, but there may be multiple real world answers based on actual community use.

A few related examples that I can think of are:

  • “concurrency model” versus “event loop” - All but one person I know refers to these singly as “the event loop”. The one odd man out initially refers to them as “the concurrency model” but whenever he does, he gets odd looks, and will switch over to “you know, the event loop”. Meanwhile, the correct terminology (as I understand it) is that many programming languages have “a concurrency model” and “the event loop” is simply JavaScript’s concurrency model.

  • const in some languages means the variable, including all its properties, is absolutely unchangeable, i.e. “immutable”, but that isn’t the case in JavaScript. (This was a big communication problem when const was initially released, but I think it’s become less of a conceptual problem as more community members understand the distinction.)

  • “compiler” versus “transpiler” - see the differences in how these sites differentiate, or don’t differentiate, these two related terms ddg “compile versus transpile” (there was also a recent Modern Web episode on this that was also pretty good)

I mention all of this because as a developer, you’re going to run this a fair bit.
And, I encourage you to:

  1. seek the most precise and specified terminology that you can — exactly like you did with this question :sunglasses:
  2. use the most precise and specified terminology that you can in discussions — to help remove ambiguity for others :woman_student:
  3. accept that language can be ambiguous and is always evolving — so that you can continue to level up your own knowledge and maintain some peace of mind :wink:
1 Like

Thanks for the detailed reply!

Re. 3 - Yes, of course I accept that language is continuously evolving and may change its meaning according to context etc. it’s just that I find it hard enough to solve the problems when the terminology is clear and unambiguous.

In an ideal world explanations would refer to e.g. the property key and the property value and much ambiguity would be eliminated, giving us the ‘peace of mind’ necessary for solving the actual problem.

It seems to me that coding is one area of language where pedantry is a virtue.

But, alas, we’re not in an ideal world so I completely take your point, and shall from now on embrace the ambiguity (while looking for and using the correct terminology myself as far as I’m able)!

:slight_smile:

1 Like

Sadly, I’ve seen devs that get so bogged down in pedantic details that they never make meaningful progress forward. As long as a person doesn’t go to that extreme, then I absolutely agree that:

… coding is one area of language where pedantry is a virtue

:yellow_heart:

You’ll see some terms used interchangeably.

  • You’ll see people use “property” to mean a key-value pair, where firstName is the “property key” and 'Bill' is the property “value”.
  • You’ll see poeple use “property” to mean a key-value pair where firstName is the “property name” and 'Bill' is the “property contents”.
  • You’ll see variations on the two above
  • You’ll see people just refer to firstName as the “property” because we’re lazy.
  • You might even see these things referred to as “members”, “data values”, or something else if the person you’re talking to comes from a different background

This may be pretty frustrating right now, but before you know it you’ll understand what people are talking about from context just like you do in spoken language.

1 Like

OK, understood, thanks :slight_smile:

To be fair., the language itself leads to the confusion.

Example:

hasOwnProperty

I mean., it really should say hasOwnPropertyName

1 Like

It does!

I’d prefer hasOwnPropertyKey … or hasOwnKey.

I wonder if Mozilla would consider changing it? I’ll write them an email :laughing:

1 Like

Mozilla doesn’t make the rules, just explain them.

If you’re curious about web standards organizations:
https://www.webstandards.org/learn/external/orgs/index.html

1 Like

I was joking, but thanks for the info.

1 Like

:smiley: Fair enough.

1 Like