Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.teledata-fn.de!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="UTF-8" Message-ID: <3004275.SPkdTlGXAF@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Tue, 29 Nov 2011 13:28:40 +0100 User-Agent: KNode/4.4.11 Content-Transfer-Encoding: 8Bit Subject: Re: Declarations (esp. of Globals) Newsgroups: comp.lang.javascript References: <78g8d712uedb7c0ugjgpdrkeg8lnugta14@4ax.com> Followup-To: comp.lang.javascript MIME-Version: 1.0 Lines: 43 NNTP-Posting-Date: 29 Nov 2011 13:28:41 CET NNTP-Posting-Host: c5c173bf.newsspool2.arcor-online.net X-Trace: DXC=kin49JKQe1E^B]`=U:WelBA9EHlD;3YcB4Fo<]lROoRA8kFNDZm8W4\YJNL;?f@h5gMfbL2UGAQ<03n7Fb87RBT;]_PE X-Complaints-To: usenet-abuse@arcor.de Xref: x330-a1.tempe.blueboxinc.net comp.lang.javascript:8700 Mike Duffy wrote: > Gene Wirchenko wrote […]: >> I am a stickler for declarations and prefer to declare >> everything. As applied to JavaScript, what say you? And why? > > I agree 100%. In the case of Javascript, even more so. There is no "Javascript" [1]. However, in ECMAScript implementations like JavaScript, JScript, etc., variable declarations are important: If you do not declare an identifier a variable, and assign to it, one of three things can happen: nothing (no effect at all, because an existing property was read-only), an exception is thrown (because an existing property could not be overwritten or created), or a property of the global object is being created or overwritten (sometimes called an "implied global"). With a variable declaration, the scope of a standalone identifier is clear. That is why in ECMAScript Edition 5.x's Strict Mode¹, such an assignment, if the identifier cannot be resolved, always throws a ReferenceError exception. You can attempt to trigger Strict Mode with "use strict"; on top of the code or function body. See also: PointedEars ___________ ¹ not to be confused with layout engines' Standards (Compliance) Mode [1] -- Prototype.js was written by people who don't know javascript for people who don't know javascript. People who don't know javascript are not the best source of advice on designing systems that use javascript. -- Richard Cornford, cljs,