I was wondering if it is possible to override "undefined" for uninitiated keys of an object such that:
var obj={} console.log(obj.randomKey) output in console: 0 I am well aware that I "forgot" to initate obj.randomKey. That is in fact my question.
Can I have a default value for any uninitiated key of an object or a class?
If you are curious
The reason I am asking is that I am trying to solve a riddle that allows creation of object with "native" language such as:
const jane = new Thing('Jane') jane.name // => 'Jane' // can define boolean methods on an instance jane.is_a.person jane.is_a.woman jane.is_not_a.man jane.is_a_person // => true jane.is_a_man // => false And this is the first strategy I am taking :)
Update: I solved the riddle :) If anyone's interested in trying: https://www.codewars.com/kata/the-builder-of-things/train/javascript