Another round of hate on JavaScript

January 12, 2024

Even with TypeScript, the syntax in JavaScript is so overloaded and bolted-on after-the-fact, it's so easy to confuse one syntax for another. Observe.

 // regular object
a = { foo: foo }


// property value shorthand
a = { foo }


// destructuring
{ foo } = a
[ foo ] = a
{ foo, bar } = a


// aliases
{ foo : bar } = a


// typescript typing
{ foo } : bar = a
foo: Foo = { a: 1, foo}


// arranged in order to highlight confusing overlap:
{ foo : bar } = a  // aliasing
{ foo , bar } = a  // destructuring
{ foo } : bar = a  // typescript typing
{ foo } : { foo : Bar } = a // typing with anonymous object type
func = (foo: {biz: Baz}): { foo : Bar } => {} // arrow function declaration with anonymous object type
a = { foo : bar }  // regular object
{ foo : baz } : { foo : bar } = a // destructuring with aliasing with an anon object type

Contact me at byronka (at) msn.com