DevTools Tip of the day: The Console dollars

$0

$0 is a reference to the currently selected html node in the Elements pane.
Also, $1 is the one selected previously, $2 the one before that, etc. up to the number $4.
You can use that additional references to try out some relative operati…


This content originally appeared on DEV Community and was authored by Ishtiaq Syed

$0

$0 is a reference to the currently selected html node in the Elements pane.
Also, $1 is the one selected previously, $2 the one before that, etc. up to the number $4.
You can use that additional references to try out some relative operations
(e.g. $1.appendChild($0))

Alt Text

$ and $$

$ in the console is an alias for the lengthy document.querySelector method.
That’s if you don’t already have $ variable defined in your app (e.g. jQuery)
$$ is an even bigger timesaver, because it not only runs document.QuerySelectorAll but also returns an array of nodes instead of NodeList type.
Basically: Array.from(document.querySelectorAll('div')) === $$('div')
Much shorter!

Picture showing how $ and $$ variable is used

$_

The $_ variable references the result of the last evaluated expression.

Picture showing how $_ variable is used

$i

With the Console Importer browser extension for Chrome you can quickly import and play with npm libraries right in the console.
Just run e.g. $i('lodash') or $i('moment') and after a couple of seconds you have lodash / momentjs available.

Picture showing how $i variable is used


This content originally appeared on DEV Community and was authored by Ishtiaq Syed


Print Share Comment Cite Upload Translate Updates
APA

Ishtiaq Syed | Sciencx (2021-06-01T18:08:07+00:00) DevTools Tip of the day: The Console dollars. Retrieved from https://www.scien.cx/2021/06/01/devtools-tip-of-the-day-the-console-dollars/

MLA
" » DevTools Tip of the day: The Console dollars." Ishtiaq Syed | Sciencx - Tuesday June 1, 2021, https://www.scien.cx/2021/06/01/devtools-tip-of-the-day-the-console-dollars/
HARVARD
Ishtiaq Syed | Sciencx Tuesday June 1, 2021 » DevTools Tip of the day: The Console dollars., viewed ,<https://www.scien.cx/2021/06/01/devtools-tip-of-the-day-the-console-dollars/>
VANCOUVER
Ishtiaq Syed | Sciencx - » DevTools Tip of the day: The Console dollars. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/06/01/devtools-tip-of-the-day-the-console-dollars/
CHICAGO
" » DevTools Tip of the day: The Console dollars." Ishtiaq Syed | Sciencx - Accessed . https://www.scien.cx/2021/06/01/devtools-tip-of-the-day-the-console-dollars/
IEEE
" » DevTools Tip of the day: The Console dollars." Ishtiaq Syed | Sciencx [Online]. Available: https://www.scien.cx/2021/06/01/devtools-tip-of-the-day-the-console-dollars/. [Accessed: ]
rf:citation
» DevTools Tip of the day: The Console dollars | Ishtiaq Syed | Sciencx | https://www.scien.cx/2021/06/01/devtools-tip-of-the-day-the-console-dollars/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.