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: why the ! operator can be used to determine a string is null? Date: Wed, 09 Aug 2017 23:35:50 +0100 Organization: A noiseless patient Spider Lines: 52 Message-ID: <87zib8e5dl.fsf@bsb.me.uk> References: <87zib8g4eb.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="095bb2b259dd0e10cf340db4dcb09e7e"; logging-data="9270"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/mcIFAVbJNj0CrpBAR7YTQihd+pbUiGu8=" Cancel-Lock: sha1:28eqPCjq6X7351X1T18tnL0vfiA= sha1:UW3Jf1/tWb/jqkD6f2/kwUCIelY= X-BSB-Auth: 1.460224f327e856bfa3ce.20170809233550BST.87zib8e5dl.fsf@bsb.me.uk Xref: csiph.com comp.lang.javascript:33743 "Evertjan." writes: > Ben Bacarisse wrote on 09 Aug 2017 in > comp.lang.javascript: > >> "Evertjan." writes: >> >>> Jon Ribbens wrote on 09 Aug 2017 in >>> comp.lang.javascript: >>> >>>> Unfortunately people tend to be very imprecise as to the meaning of >>>> the phrase "null string", and may variously mean either the actual >>>> null value or an empty string. >>> >>> Indeed, >>> a string is NEVER null, >>> because then it is NOT a string. >> >> Further complicated by the fact that there is a character called null >> (sometimes Null, Nul or NULL) so a string can "be null" in that it >> contains just that character. It's not a clear way to speak about such >> things but we're all guilty of using short-hands now and again. > > Not true. > > Whoever "speaks" in code anyway? No one. I said a "way to speak about such things". > let myString = null; > > ...is not a character, not is it the number zero. Of course not. I was talking about a string with a single NULL character in it (was the not clear?). For example: let myString = "\u0000"; Note that all I am saying is that the presence of a character called NULL (or null, etc.) complicates things even more, and leads some (bad, very bad!) people to use incorrect language. I get the feeling this is contentious because I've said it, rather than there being any real disagreement. People might, in an off-hand sort of way say "here is is a question-mark: var s = '?';" and they might also so say "here is a null: var s = '\0';". Of course they are very, very wrong to even think of saying that, but to suggest that they might is not outrageous, much less to say that doing so would add to the confusion already noted. -- Ben.