I was playing around in Node and accidentally mistyped the curly brackets ({}
) and put square brackets ([]
) instead, and started using the variable as a simple object. No error has been thrown, and the behaviour seems to be the same, but when I checked the type with Object.getPrototypeOf()
they were different.
> var cake = [];
> cake["is_a"] = "lie";
> cake
[ is_a: 'lie' ]
> Object.getPrototypeOf(cake.is_a)
[String: '']
> Object.getPrototypeOf(cake)
[]
> Object.getPrototypeOf({})
{}
Then I thought that this is a syntactic sugar on top of arrays, but no:
> cake[0]
undefined
It reminds me of Elixir's keyword lists or Erlang's property lists. What are they called? (So that I can google further.) Are these specific to Node?