3

In Chrome, this fiddle prints false. However, the same code typed in the JavaScript console prints true:

a = 1;
var a = 2;
console.log(delete a);​

Why do I get different results depending on whether or not I'm using the Chrome console?

2
  • any particular reason for doing this? :) Commented Sep 14, 2012 at 23:47
  • 1
    Pasting this into console gives SyntaxError: Unexpected token ILLEGAL, Chrome (Linux) Commented Sep 14, 2012 at 23:48

2 Answers 2

1

Because the Chrome console runs inside an eval construct or something similar, rather than running in the global scope.

There is a lot of discussion about the delete operator here on StackOverflow. A search for [javascript] delete will help answer other questions that come up.

Sign up to request clarification or add additional context in comments.

Comments

0

var defined variables can not be deleted.

1 Comment

Apparently you can in the Chrome console, though, which is the OPs question. I tried it myself; he's right.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.