@jgCarroll/

objectProperties

JavaScript

A common interview question.

fork
loading
main.js
1
2
3
4
5
6
7
8
9
10
const a = {};
const b = { name: 'b' };
const c = { name: 'c' };
 
a[b] = 200; // placing an object as a property on another object. Not allowed. Only strings can be properties on objects
a[c] = 400;
 
console.log(a[b]); // logs 400

console.log(a) // logs { '[object Object]': 400 }
Native Browser JavaScript