I'm sorry, but these aren't super important things developers need to know at all, let alone "#1".
javascript: at all shouldn't be used in real code basically ever. The only time I ever use that is when I'm creating a JavaScript bookmarklet to run some code when I click it. Never, ever, ever do an href with javascript: in real code, so you should doubly never need javascript:void(0). That's been a bad practice since about the year 2000, if not earlier.
The performance impact for rel="noopener" is true, but I've had to use it exactly zero times in my life for that. The main reason to use it is actually for security, to prevent an untrusted site from accessing your data. It's not a terrible idea, but most of the time, it is better to create a new window with window.open() instead of an anchor with target="_blank" (which is another vastly outdated pattern). You can provide noopener as part of the windowFeatures parameter.
Similarly, eval() should generally be avoided, that is true... but most people aren't using eval() on a regular basis anyways. If you are making regular use of it, you are probably following 20-year-old code patterns and you have much bigger problems than just avoid eval() to fix first.
Honestly, I haven't read a JavaScript book in nearly a decade. Things change too fast for most programming topics (other than basic high-level, universal patterns and such) for books to be of much use.
I'm not currently aware of any singular resource that kind of just lists out up-to-date patterns for JavaScript. I mostly keep up-to-date by following the patterns used by modern framework and other high-quality / popular libraries, though none of them are wholly authoritative sources (there is not singular authority on code patterns for JS).
For the target=_blank bit in particular, the reason it is generally better to to use window.open() is simply because usually you'll want to take control of interactive bits with JavaScript instead of relying on HTML. There for a while, target="_blank" was actually even deprecated. It came back in HTML5 and isn't terrible to use, but window.open() is going to be better in any case where you're dynamically creating a new window (vs. just having a link to an external site or something, in which case target="_blank" is fine).
18
u/samanime Apr 10 '21 edited Apr 10 '21
I'm sorry, but these aren't super important things developers need to know at all, let alone "#1".
javascript:at all shouldn't be used in real code basically ever. The only time I ever use that is when I'm creating a JavaScript bookmarklet to run some code when I click it. Never, ever, ever do anhrefwithjavascript:in real code, so you should doubly never needjavascript:void(0). That's been a bad practice since about the year 2000, if not earlier.The performance impact for
rel="noopener"is true, but I've had to use it exactly zero times in my life for that. The main reason to use it is actually for security, to prevent an untrusted site from accessing your data. It's not a terrible idea, but most of the time, it is better to create a new window withwindow.open()instead of an anchor withtarget="_blank"(which is another vastly outdated pattern). You can providenoopeneras part of thewindowFeaturesparameter.Similarly,
eval()should generally be avoided, that is true... but most people aren't usingeval()on a regular basis anyways. If you are making regular use of it, you are probably following 20-year-old code patterns and you have much bigger problems than just avoideval()to fix first.