r/javascript • • Jul 11 '17

help What 10 Things Should a Serious Javascript Developer Know Right Now?

I'm inviting pure opinion here, but what's your list of ten things that everyone looking for a good javascript role should know and understand. Personally, I'm in a role where what I know is adequate, but I want to be somewhere better; somewhere that has some flippin standards. I'm learning outside of work requirements at the moment, but there is so much shit to learn out there.

The objective is to do good work in a good place.

Narrow it down to your ten for me, or for you.

Can be your own "I must learn x" list too. I'm very interested to hear what people think.

348 Upvotes

223 comments sorted by

View all comments

Show parent comments

42

u/junior-dev Jul 11 '17

Can you source your x2800 claim against document.querySelector?

I can't tell if you're exaggerating or not. 2800 seems too specific to be an exaggeration, so I don't think you are.

I concede that document.getElementById``document.getElementsByTagName and document.getElementsByClassName are faster than document.querySelector and document.querySelectorAll respectively -- by an order of magnitude of 10, and maybe even 100. But not 1000.

I haven't found any evidence for a speed factor of ~2800.

Generally, people are curious about performance, so I've found several JSPerf tests for this.

https://jsperf.com/getelementbyid-vs-queryselector/11

https://jsperf.com/queryselectorall-vs-getelementsbytagname

https://jsperf.com/getelementsbyclassname-vs-queryselectorall/18

In the 2nd one, the difference is quite stark: ~x300 speed increase for document.getElementsByTagName.

But it's not ~2800, none of them are. I understand that these are isolated cases, a bit contrived and unrealistic. But can you come up with any test case that would demonstrate x2800?

I just don't believe it.

26

u/slapfestnest Jul 11 '17

duuuudee, don't be An Imposter!! /s

2

u/PeacefulOni Dec 09 '17

LOL I chuckled at that too. I don't think I've actually heard someone say the term imposter outside of saying imposter syndrome.

8

u/tylercamp Jul 11 '17

It definitely sounds fishy since I imagine it's just a wrapper over the more specific DOM methods with a simple parser on top

1

u/[deleted] Jul 11 '17

[removed] — view removed comment

1

u/turkish_gold Jul 12 '17

From the charts, it looks like newer browsers are getting better at executing getElementById and others in tight inner-loop testing conditions.

1

u/del_rio Jul 11 '17

I think you're a bit too rigid with your interpretation. I'm guessing he's referring to using query selectors without caching the results.

document.querySelector("div.user-panel.main input[name='login']").addEventListener('click', something);

vs

userPanelEl.children[0].addEventListener('click', something)

Newer/less experienced devs often rely on jQuery selectors but never cache them.

12

u/leeharris100 Jul 11 '17

Then the guys point was stupid.

That has nothing to do with query selector speed.

6

u/Pandalicious Jul 11 '17

You guys are getting lost in the weeds. OP's main point is that js developers should have a solid understanding of the DOM. Many newer front end developers only have a fuzzy understanding of the DOM and think of JavaScript as something that dynamically modifies the static HTML text that they write.

1

u/[deleted] Jul 11 '17

2

u/junior-dev Jul 11 '17

2nd Experiment on Chrome 59: x88.2 faster

3rd Experiment on Chrome 59: x27.9 faster

This supports my argument even more. The speed increase is within the 10s, not even 100s, let alone 1000s.

2

u/[deleted] Jul 11 '17 edited Jul 12 '17

The second test shows a difference of 16231.985x in FF52 and a difference of 9248.422x in FF54. Those are some serious WTF numbers and FF54 shows a difference of 6987.384x in test 3.

Some food for thought:

  • The driving distance from Anchorage, AK to Miami, FL is 4976 miles and when divided by 16231.985 is only a quarter of a mile (1618 feet).

  • 1 second times 16231.985 is more than 4.5 hours.

  • It is also the difference between 32 minutes and a year.

  • Or 2.25 days and a century.

  • Or 2 inches and the total height of the Burj Kalifa.

  • Or the difference in mass between the largest recorded blue whale and an average domestic cat.

1

u/esantipapa Jul 11 '17

So, higher Ops/sec = more efficient code?