Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: comp.lang.javascript Subject: Re: How would you prepare for javascripting interview? Date: Sat, 10 Sep 2016 15:49:56 +0100 Organization: A noiseless patient Spider Lines: 35 Message-ID: <87r38ru7vv.fsf@bsb.me.uk> References: <50e38667-93da-4c5d-bc02-a78394f0ca3b@googlegroups.com> <1875389.irdbgypaU6@PointedEars.de> <8rn7tb5sl4gea5mricmn7rvemv1kn3st3u@4ax.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="017616aa25f81ec581c44d76d61ba2f3"; logging-data="30269"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18gjR7tF4YvSHJiaTrBILIXm0cQzeoxmRI=" Cancel-Lock: sha1:kXE8minDvQ3RqtlOR6Z8BBOuYQ0= sha1:BqF90Joty3CxCTbhYJXEqltRFgg= X-BSB-Auth: 1.90c8eec40755bda80106.20160910154956BST.87r38ru7vv.fsf@bsb.me.uk Xref: csiph.com comp.lang.javascript:31303 John Harris writes: > On Sat, 10 Sep 2016 02:14:36 -0000 (UTC), Scott Sauyet > wrote: > > >>-Infinity is a number. It's a valid number that can be used in >>comparisons, in further `max` calls, even in much arithmetic. Granted, >>it might not be the best for final displays, but as these should always >>be pushed to the edges of your program, it's pretty easy to handle these >>in a single place. > > > -Infinity is an ECMAScript Number, but not a genuine number (lower > case n), though it is sometimes used in maths to signal don't know, > undefined, keep going, etc. Since the discussion is about ECMAScript, using -Infinity makes perfect sense. What's more, ECMAScript states when the result of arithmetic operations will be +/-Infinity, and it mandates what results are to returned from expressions involving these quantities. > If you want a number it would be far more logical to use > -Number.MAX_VALUE. If the application is restricted to integers then > that would be -Number.MAX_SAFE_INTEGER. Then, for some values of list, you could have Math.max.apply(null, []) > Math.max.apply(null, list) If Math.max is going to return a value at all (and I think it's reasonable to do so) the -Infinity is the only reasonable choice. -- Ben.