Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #17999 > unrolled thread
| Started by | Thomas Li <cooooooder@gmail.com> |
|---|---|
| First post | 2013-01-07 01:21 -0800 |
| Last post | 2013-01-07 21:48 -0800 |
| Articles | 7 — 5 participants |
Back to article view | Back to comp.lang.javascript
Global variable is deletable? Thomas Li <cooooooder@gmail.com> - 2013-01-07 01:21 -0800
Re: Global variable is deletable? Stefan Weiss <krewecherl@gmail.com> - 2013-01-07 11:24 +0100
Re: Global variable is deletable? JJ <jaejunks@nah.meh> - 2013-01-07 15:36 +0000
Re: Global variable is deletable? Scott Sauyet <scott.sauyet@gmail.com> - 2013-01-07 07:50 -0800
Re: Global variable is deletable? Thomas Li <cooooooder@gmail.com> - 2013-01-07 22:08 -0800
Re: Global variable is deletable? dann90038@gmail.com - 2013-01-07 13:25 -0800
Re: Global variable is deletable? Thomas Li <cooooooder@gmail.com> - 2013-01-07 21:48 -0800
| From | Thomas Li <cooooooder@gmail.com> |
|---|---|
| Date | 2013-01-07 01:21 -0800 |
| Subject | Global variable is deletable? |
| Message-ID | <95a66842-702a-416d-9575-e47c82e6667e@googlegroups.com> |
Hi, I'm fresh in Javascript. From the book "Javascript, the definitive guide", the global variable should be nondeletable, however when I test it in IE, it is deletable, anything wrong? Steps: 1. Open IE 9 2. Press F12 and select Console panel 3. Var temp = 1; delete temp; 4. it returns true and when I enter temp, it says "temp is undefined"
[toc] | [next] | [standalone]
| From | Stefan Weiss <krewecherl@gmail.com> |
|---|---|
| Date | 2013-01-07 11:24 +0100 |
| Message-ID | <kce7oa$h9o$1@news.albasani.net> |
| In reply to | #17999 |
On 2013-01-07 10:21, Thomas Li wrote: > Hi, I'm fresh in Javascript. From the book "Javascript, the > definitive guide", the global variable should be nondeletable, > however when I test it in IE, it is deletable, anything wrong? > Steps: > 1. Open IE 9 > 2. Press F12 and select Console panel > 3. Var temp = 1; > delete temp; > 4. it returns true and when I enter temp, it says "temp is undefined" When you enter something in the console, it gets evaluated with eval(). Variables created from eval()ed code don't have the DontDelete flag set. Details: http://perfectionkills.com/understanding-delete/#firebug_confusion - stefan
[toc] | [prev] | [next] | [standalone]
| From | JJ <jaejunks@nah.meh> |
|---|---|
| Date | 2013-01-07 15:36 +0000 |
| Message-ID | <XnsA141E6C0BB03Bjj@0.0.0.17> |
| In reply to | #18001 |
Stefan Weiss <krewecherl@gmail.com> wrote: > On 2013-01-07 10:21, Thomas Li wrote: >> Hi, I'm fresh in Javascript. From the book "Javascript, the >> definitive guide", the global variable should be nondeletable, >> however when I test it in IE, it is deletable, anything wrong? >> Steps: >> 1. Open IE 9 >> 2. Press F12 and select Console panel >> 3. Var temp = 1; >> delete temp; >> 4. it returns true and when I enter temp, it says "temp is undefined" > > When you enter something in the console, it gets evaluated with eval(). > Variables created from eval()ed code don't have the DontDelete flag set. > > Details: > http://perfectionkills.com/understanding-delete/#firebug_confusion > > > - stefan I'd toss that book. <!DOCTYPE html> <html> <body> <script> console.log(typeof abc); //undefined abc=123; console.log(typeof abc); //number delete abc; console.log(typeof abc); //undefined </script> </body> </html>
[toc] | [prev] | [next] | [standalone]
| From | Scott Sauyet <scott.sauyet@gmail.com> |
|---|---|
| Date | 2013-01-07 07:50 -0800 |
| Message-ID | <d46aaa01-3855-494d-82ce-892363103d03@s14g2000yqg.googlegroups.com> |
| In reply to | #18008 |
JJ wrote:
> Stefan Weiss wrote:
>> On 2013-01-07 10:21, Thomas Li wrote:
>>> Hi, I'm fresh in Javascript. From the book "Javascript, the
>>> definitive guide", the global variable should be nondeletable,
>>> however when I test it in IE, it is deletable, anything wrong?
>>> Steps:
>>> 1. Open IE 9
>>> 2. Press F12 and select Console panel
>>> 3. Var temp = 1;
>>> delete temp;
>>> 4. it returns true and when I enter temp, it says "temp is undefined"
>
>> When you enter something in the console, it gets evaluated with eval().
>> Variables created from eval()ed code don't have the DontDelete flag
>> set.
>
>> Details:
>> http://perfectionkills.com/understanding-delete/#firebug_confusion
> I'd toss that book.
>
> <!DOCTYPE html>
> <html>
> <body>
> <script>
> console.log(typeof abc); //undefined
> abc=123;
> console.log(typeof abc); //number
> delete abc;
> console.log(typeof abc); //undefined
> </script>
> </body>
> </html>
Back away from the trash can with that book!
Undeclared assignment does not set the DontDelete attribute. If you'd
read the article Stefan mentioned, I'm sure you would have seen that.
(I'm not going to re-read it now to find out where, but I'm pretty
sure that kangax's article is where I learned it in the first place.)
console.log(typeof abc); //undefined
var abc = 123;
// ^^^
console.log(typeof abc); //number
delete abc; // false
console.log(typeof abc); //number
-- Scott
[toc] | [prev] | [next] | [standalone]
| From | Thomas Li <cooooooder@gmail.com> |
|---|---|
| Date | 2013-01-07 22:08 -0800 |
| Message-ID | <35ea2ee1-1ad3-4c31-a4c6-b883b7b4db88@googlegroups.com> |
| In reply to | #18001 |
On Monday, January 7, 2013 6:24:10 PM UTC+8, Stefan Weiss wrote: > On 2013-01-07 10:21, Thomas Li wrote: > > > Hi, I'm fresh in Javascript. From the book "Javascript, the > > > definitive guide", the global variable should be nondeletable, > > > however when I test it in IE, it is deletable, anything wrong? > > > Steps: > > > 1. Open IE 9 > > > 2. Press F12 and select Console panel > > > 3. Var temp = 1; > > > delete temp; > > > 4. it returns true and when I enter temp, it says "temp is undefined" > > > > When you enter something in the console, it gets evaluated with eval(). > > Variables created from eval()ed code don't have the DontDelete flag set. > > > > Details: > > http://perfectionkills.com/understanding-delete/#firebug_confusion > > > > > > - stefan Great thanks and the reference is very helpful
[toc] | [prev] | [next] | [standalone]
| From | dann90038@gmail.com |
|---|---|
| Date | 2013-01-07 13:25 -0800 |
| Message-ID | <5d9d193f-fb91-43bd-a82d-0528f3ccdd3e@googlegroups.com> |
| In reply to | #17999 |
-> Thomas Li I have JS Definitive Guide 5th edition, on chapter 4.2 as you read on the last paragraph of that section: ----------------------------- Variables declared with var are permanent: attempting to delete them with the delete operator causes an error. (The delete operator is introduced in Chapter 5.) ----------------------------- I gather you misunderstood the statement. The paragraph refers to the limits the 'delete' operator capability, as you could see at -> http://www.webdevout.net/test?016&raw
[toc] | [prev] | [next] | [standalone]
| From | Thomas Li <cooooooder@gmail.com> |
|---|---|
| Date | 2013-01-07 21:48 -0800 |
| Message-ID | <59c0b6b0-f9ef-44a0-9178-43f16fdf88af@googlegroups.com> |
| In reply to | #18010 |
On Tuesday, January 8, 2013 5:25:57 AM UTC+8, dann...@gmail.com wrote: > -> Thomas Li > > > > I have JS Definitive Guide 5th edition, on chapter 4.2 as you read on the last paragraph of that section: > > ----------------------------- > > Variables declared with var are permanent: attempting to delete them with the delete operator causes an error. (The delete operator is introduced in Chapter 5.) > > ----------------------------- > > > > I gather you misunderstood the statement. The paragraph refers to the limits the 'delete' operator capability, as you could see at -> http://www.webdevout.net/test?016&raw Great thanks for your help :)
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web