What is better to use for performance in JavaScript?
document.children[0].children[1]
vs
document.querySelector('body')
Which is more faster in performance?
Here you've the result from fast to slow:
document.body (by far)document.querySelector('body'), document.children[0].children[1], document.getElementsByTagName('body')[0] (about the same)document.querySelectorAll("body")[0], $('body')
Source JSBench (try it yourself)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With