Home  >  Article  >  Web Front-end  >  What does the $ Variable Represent in the Chrome Developer Console?

What does the $ Variable Represent in the Chrome Developer Console?

Barbara Streisand
Barbara StreisandOriginal
2024-10-22 12:17:02468browse

What does the $ Variable Represent in the Chrome Developer Console?

Native Function Referred by $ in Chrome

In the developer tools of Google Chrome, the $ variable holds a function accessible only through the console. Despite attempts to access it via various objects ($window, $document, $this), its purpose remains unknown.

Resolution

The behavior of $ in Chrome's console has evolved over time. Currently, it serves as an alias for document.querySelector(), enabling the selection of the first DOM element matching a CSS selector. Additionally, the console provides several other shortcuts, including:

  • $$(selector): Returns an array of elements matching a CSS selector (equivalent to document.querySelectorAll())
  • $_: Returns the value of the most recently evaluated expression
  • $0 to $4: Provide historical references to recently inspected DOM elements or JavaScript heap objects

It's important to note that, while $ is an alias of document.querySelector(), $$ returns an array, and neither is strictly equal to its respective object method (e.g., $ !== document.querySelector()).

The above is the detailed content of What does the $ Variable Represent in the Chrome Developer Console?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn