var x = 3; Object.defineProperty(window, "x", { get : function(){ return this._x; }, set : function(value){ this._x = value; if (value == 5) { console.log("x == 5"); } } }); x = 5;