Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #27836
| Newsgroups | comp.lang.javascript |
|---|---|
| Subject | Re: Identity of values in Javascript |
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
| References | <555f256b$0$12988$c3e8da3$5496439d@news.astraweb.com> <87r3q8h3yf.fsf@bsb.me.uk> <555f7d3b$0$13002$c3e8da3$5496439d@news.astraweb.com> |
| Date | 2015-05-22 23:51 +0200 |
| Message-ID | <XnsA4A2F2B9BA114eejj99@194.109.133.246> (permalink) |
Steven D'Aprano <steve@pearwood.info> wrote on 22 mei 2015 in comp.lang.javascript: > Ah, thanks again for the correction. > > I only need to use the var declaration once, correct? If I say: > var x = 23; > then later > x = 42; > the second assignment applies to the same x variable as the first. > Correct? Well, x is just a "pointer to a hidden location" where the value is stored. We call it a variable, a pointer would be more correct, imho. If you overwrite the x in the sense of storing another value "in it", it could very well be the pointer now points to another location. Locations that have lost their pointer [or all pointers] will be garbage-collected. Since an object and an array point to a location of a collection of pointers the manipulations have more a feeling of "by reference". var a = 17; var b; b = a; // just copies the VALUE of a in b. b = 3; // won't change the value "in" a. alert(a); // 17 var c = ['qqq',3]; alert(c[0]); // qqq var d; d = c; // copies the LOCATION of the array. d[0] = 'xxx'; // will change c[0] too. alert(c[0]); // xxx // however if you now do: c = 'blah'; // the c as pointer to the array is lost, and: alert(d[0]); // xxx // d is now the only pointer to the original array Perhaps it does not feel right, but that is just the way it is. -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Identity of values in Javascript Steven D'Aprano <steve@pearwood.info> - 2015-05-22 22:47 +1000
Re: Identity of values in Javascript Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-22 19:17 +0100
Re: Identity of values in Javascript Steven D'Aprano <steve@pearwood.info> - 2015-05-23 05:02 +1000
Re: Identity of values in Javascript Steven D'Aprano <steve@pearwood.info> - 2015-05-23 05:25 +1000
Re: Identity of values in Javascript "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-05-22 23:51 +0200
Re: Identity of values in Javascript Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-23 00:24 +0100
Re: Identity of values in Javascript Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-05-23 09:35 +0200
Re: Identity of values in Javascript Steven D'Aprano <steve@pearwood.info> - 2015-05-23 23:04 +1000
Re: Identity of values in Javascript "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-05-23 22:27 +0200
Re: Identity of values in Javascript Steven D'Aprano <steve@pearwood.info> - 2015-05-25 01:58 +1000
Re: Identity of values in Javascript Steven D'Aprano <steve@pearwood.info> - 2015-05-25 02:12 +1000
Re: Identity of values in Javascript Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-24 23:33 +0100
Re: Identity of values in Javascript Steven D'Aprano <steve@pearwood.info> - 2015-05-25 21:47 +1000
Re: Identity of values in Javascript Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-26 00:10 +0100
Re: Identity of values in Javascript Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-05-26 17:34 +0200
Re: Identity of values in Javascript Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-26 17:03 +0100
Re: Identity of values in Javascript Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-05-26 18:31 +0200
Re: Identity of values in Javascript Steven D'Aprano <steve@pearwood.info> - 2015-05-27 23:40 +1000
Re: Identity of values in Javascript Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2015-05-27 23:21 -0300
Re: Identity of values in Javascript "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2015-05-27 19:32 -0700
Re: Identity of values in Javascript Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-05-28 22:38 +0200
Re: Identity of values in Javascript Scott Sauyet <scott.sauyet@gmail.com> - 2015-05-26 09:06 -0700
Re: Identity of values in Javascript Steven D'Aprano <steve@pearwood.info> - 2015-05-27 23:02 +1000
Re: Identity of values in Javascript Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-05-23 00:02 +0200
Re: Identity of values in Javascript Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-05-23 09:19 +0200
Re: Identity of values in Javascript Steven D'Aprano <steve@pearwood.info> - 2015-05-23 05:20 +1000
csiph-web