So from a basic understanding of JavaScript === is faster than == (in most cases)(because === does not have to perform type-casting).
Recently I saw someone setup a high-scoped set of variables for the entire function/object/class:
var val = {}; // some random object that never changes?
var Obj = {};
then (optionally repeated) later:
Obj[key] = val;
then (optionally repeated, and possibly intertwined with above) later compared:
if ( Obj[key] === val ) {...}
My question is, why (if is it) is it faster/better than skipping val completely and just using:
Obj[key] = true; // or = 1, or something?
// ... more code, then later checking:
if ( Obj[key] === true ) // or === 1 or just ( Obj[key] ) because basic existence evaluates to true
I assume the performance lost from using true or 1 is worse than comparing an object with itself, but I'd like to understand why?
Thanks!