Policy on modern JavaScript?


Hi, I noticed that pretty much all pages on MDN use the old JavaScript syntax (var instead of let/const, no arrow functions). Is there a specific reason why we keep using this syntax, or can I replace it by the new syntax when updating a page?

I suppose that on the one hand, modern syntax is better because new JavaScript developers will not learn outdated JavaScript, on the other hand, the code examples should be ready for copy & pasting into production code, where the code will not work on some older browsers without transpiling.

Other than that, when it comes to indentation, or using quotes vs. apostrophes, I would follow the popular airbnb style guide. Is that fine or do you have a different style guide?


Nevermind, I totally missed that there was already a recent discussion on this: JS examples: style guide. So for now, it looks like we are sticking with ES5, though I hope this will change soon.

(Chris Mills) #3

Yeah, we’ve had this conversation a few times.

We used to be very against using modern JS syntax because of the reasons you cite, and because some people don’t understand it yet. Using old style syntax is the best way to maximise the possibility of the reader understanding it.

However, it is a bad idea for a modern web development site to be against modern JS! Especially when some new JS and API features don’t make sense with older JS syntax, e.g. promise-based APIs, async/await, etc.

So we have relaxed our view on this recently. I would actually say that sticking to the airbnb guide is fine. We are meaning to update our guide pages soon.

(Eric Shepherd) #4

I think we should gradually ease our way into it. Certainly we don’t want to hit new developers with too much at once, so we need to use caution with when and where we transition to ES6 constructs, but I agree that we do want to move in that direction over time.

I feel that for now at least the first example on most pages—except for particularly advanced topics—should remain ES5; further examples might be more flexible (although perhaps sometimes with links to the docs for the constructs used, when it can be done without being obtrusive).

Eric Shepherd
Senior Technical Writer

MDN Web Docs: https://developer.mozilla.org/

Blog: http://www.bitstampede.com/

Twitter: http://twitter.com/sheppy