Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

var $1 = document.getElementById("any"); works only after executing it twice in Chrome Dev Tools

I was trying some basic code when I went through this on Chrome Developers Tools console:

enter image description here

The language specification says that you can declare a variable starting with a letter, $ or _.

So, why is this happening? Is it just a bug or does it have some other justification?
Why it doesn't work the first time but works when re-assigning?

EDIT:

I received comments about $1 to $4 been reserved identifiers, but I still don't get why it get assigned exactly the second time (instead of the first time or never being assigned)

like image 559
Alejandro Veltri Avatar asked May 16 '15 05:05

Alejandro Veltri


1 Answers

Quoting from the devtools documentation

Dev Tools remembers the last five DOM elements (or JavaScript heap objects) that you've selected in the tab (or Profiles panel). It makes those objects available as $0, $1, $2, $3, and $4. $0 returns the most recently selected element or JavaScript object, $1 returns the second most recently selected one, and so on.

these reserved identifiers will act differently from other regular identifiers in console.

hope this helps.

like image 182
shakib Avatar answered Oct 19 '22 23:10

shakib