Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!feeder1-2.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="UTF-8" Message-ID: <7998487.AcjmSas2GF@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Tue, 28 Jan 2014 15:58:34 +0100 User-Agent: KNode/4.11.3 Content-Transfer-Encoding: 8Bit X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. MIME-Version: 1.0 Lines: 39 NNTP-Posting-Date: 28 Jan 2014 15:58:37 CET NNTP-Posting-Host: f9a4aba2.newsspool2.arcor-online.net X-Trace: DXC=9Zm;XCYn4iCI7\_^6>c20JA9EHlD;3YcB4Fo<]lROoRA8kF function damn() { > this.x = 4; > var y = 3; > > setTimeout(function() {alert(this.x); alert(y)}, 100); > > this.aa = function() { > alert(this.x); > }; > } > > aaa = new damn(); > aaa.aa(); > > What would be the output?! > > The correct answer should be 4 undefined and 3. Yes, although there is a race condition and it could be “undefined”, “3”, and “4” as well. Or a SyntaxError or TypeError exception could be thrown. > I answered 4 4 3. > > The question is why this.x inside setTimeout does not alert 4? I could tell you (and probably others will, with wrong explanations in-between), but try debugging first. You will learn more for your next interview this way. -- PointedEars Twitter: @PointedEars2 Please do not Cc: me. / Bitte keine Kopien per E-Mail.