0

For example if I type

var x = 5;
x;

console output is 5 (as expected)

But when I want to start afresh and clear the console(using ctrl+L or clear(); ),the console clears up but x still contains value 5 (as can be checked by typing x in console)

I don't want console to remember any previous data after using clear.How can I do it?

1 Answers1

1

clear() does just that - clears the console.

But to add something new - you can't delete your variables, at least not when they're declared this way. The only 100% sure way of doing this, is simply refreshing the page.

To elaborate: you can delete only object's properties, so if you do this:

x = 5;
delete x; // returns true

It will work, but if you assign your value using var keyword:

var x = 5;
delete x; // returns false

...then you can't delete it.

To better understand what you can and what you can't delete and why - you can read more under this link: http://perfectionkills.com/understanding-delete/.

Michal Leszczyk
  • 1,849
  • 15
  • 19