This site is absolutely awesome and I would suggest this to new comers and experienced folks alike. It covers all things related to javascript, explains the concepts really well in a practical day to day application point of view.
I might be sounding like a promoter for it, but it really added a lot of value for me personally, so just wanted to spread the good word.
Edit: I don't mention this to be nitpicky. I mention it because I wish that we would collectively start standardizing those terms. I think it would be helpful if, whenever we saw "… guide" or "… tutorial" we had a general idea about the structure and purpose of the contents. The Divio links above do a great job at explaining each doc type. I'm simply sharing this idea for people who have never considered being more careful about how they label their docs and would like to start following general technical writing community practices. As a practicing technical writer I can tell you that the TW community mostly agrees upon what each doc type entails ("tutorials" and "references" have strong consensus; "guides" less so).
Here’s an example great bike shed discussion from ~10y ago about whether or not to use semicolons with JavaScript.
“If you don’t understand how statements in JavaScript are terminated, then you just don’t know JavaScript very well, and shouldn’t write JavaScript programs professionally without supervision, and you definitely should not tell anyone else how to write their JavaScript programs.”
I used to be on the "always use semicolons" side of this argument. Having shipped multiple projects using both methods my verdict is clear: It doesn't matter. Why it doesn't matter you ask? Because 1) I am enforcing either decision with eslint rules and 2) i write unit tests 3) code is transpiled (thus semicolons are handled perfectly at the output). Having these three in place, I have yet to encounter a single "gotcha" out of omitting semicolons.
If for any reason you absolutelly can't have these in place, better be safe and use semicolons.
Edit: for the "gotcha" explained in the link, prettier will automatically insert a semicolon before the array.
I've run into that in a few places and it always baffles me that people would intentionally choose to add even more gotchas to javascript. Don't get me wrong, I think aesthetics in code are important but not to the point of deliberately increasing the chance of hard to find bugs.
I don't know whether I use them or not, to be honest (and I just finished a project in js). My code looks like whatever the almost-default (tab-width: 4) output of prettier is.
It's nice to not waste a single braincycle on these things anymore.
Debate over one character whose presence in code has no downside other than that a subset of programmers get to feel less arrogant. Sometimes I cannot stand this industry.
For real projects, but for someone just getting started I think it makes a lot of sense to start with core language fundamentals (I notice that, at least from the table of contents, there was no mention of build systems or frameworks either). Lots of newly-minted JS devs today know relatively little about what it means to use plain JS, which means they don't have as much perspective on what their TypeScript and JSX actually turn into, which has a meaningful effect on informing decisions.
I have figured it out experimentally (Chrome & Ukrainian): if you visit a website in language X and click Never Translate, Chrome silently adds language X to the end of the list (Accept-Language that is). I have not found a way to forcibly turn it off.
Edit: check out chrome://translate-internals/ if you are interested
This was probably set at the operating system level, i.e. you selected "zh_ZH"/Chinese at some point during setup. Upon installing a browser, it reads your OS language preference & then passes that through to websites via the accept-language header.
I feel I need this so badly.
The last time I wrote something in JavaScript was around 10 years ago and I want to get up to date.
One of the chapters is named "the old 'var'". I didn't know it was old, which proves the need to learn.
Looks well written, but it seems undecided on whether it's targeting experienced programmers or newcomers. I have to disagree with priyatham_'s position that it effectively targets both.
The Loops section gives a very brief description of what loops are. This doesn't introduce anything of value to an experienced programmer, and it's nowhere near enough of an explanation for teaching imperative programming to a beginner.
Personally I'd suggest targeting experienced programmers. I only learnt JavaScript relatively recently, and I found it very frustrating that every JavaScript tutorial I could find was aimed at beginners (and that isn't an exaggeration).
For as good as the TOC and layout is, there's always something I miss when I read books from a website. I miss the spatial context: how much material I already covered? How much is left?
I like the linearity of regular books (that includes PDFs). If the book is a website the next best thing for me is when the whole thing is just a single page. Worst thing are epubs :-p (hate the way the layout works with those and how slow epub readers tend to be).
ps. I saw I can buy a PDF of this site, but just commenting in general.
Note that the Russian version of the site has more information than the English version, you can translate the page into English to read it (or just learn Russian)
This is great. However, it gives the example of copying a variable by assigning another variable to it. This doesn't copy a variable's contents - it makes the new variable a pointer to the original variable.
As someone who doesn't use Javascript much... is there a way to force it to copy the current state of the original variable to the new variable, without it being a reference and without having to use something like lodash?
You will need to clone the object somehow. The simplest solution is to go through each of the object properties and create a new object with those same properties (_.clone). Alternatively, recursively go through each property in the object and then keep going deeper through each property that is an object until you get a copy of everything to assign to a new object (_.deepClone)
I think the only reasonable thing that js can do here is what it does - copy the reference. Also, there is a simple way to copy all properties from a object: const copy = { ...object }; Of course, if these properties are themselves objects, then changes in one of them will appear in the other.
One way to have a deep copy which shares nothing is const copy = JSON.parse(JSON.stringify(object)); but that may not always work. In short, copying a arbitrarily large object will probably waste memory, so it should be a little hard so you don't do it unless it's really necessary.
In addition to the cloning stuff, I've seen use of an immutables library [0] to make this stuff a little more explicit and simple. Not sure if that's still fashionable though.
There is a chapter called ‘ninja code’, which is full of terrible advice. A small example.
> The ideal name for a variable is data. Use it everywhere you can.
There is one small comment at the top of the chapter, which says ‘Irony detected’. Is there really a whole chapter written Ironically? It would be very easy to read this and think it was real advice.
(And if it is real advice, and I’m completely misunderstanding, then I can’t possibly recommend this book).
Aside from newer methods the only syntax gotchas in my code are template strings and let/const. That makes the code really quick and simple to convert to an old IE friendly application.
I've had this site's Regex section bookmarked for awhile and it's been a great tutorial and reference. I can't speak to the other content but if it's similar, it would be of good quality.
[+] [-] priyatham_|5 years ago|reply
I might be sounding like a promoter for it, but it really added a lot of value for me personally, so just wanted to spread the good word.
[+] [-] simonw|5 years ago|reply
[+] [-] mekoka|5 years ago|reply
https://news.ycombinator.com/from?site=javascript.info
I sometimes wonder what are the dynamics that trigger the snowball on HN.
[+] [-] kaycebasques|5 years ago|reply
[1]: https://documentation.divio.com/tutorials/
[2]: https://documentation.divio.com/how-to-guides/
Edit: I don't mention this to be nitpicky. I mention it because I wish that we would collectively start standardizing those terms. I think it would be helpful if, whenever we saw "… guide" or "… tutorial" we had a general idea about the structure and purpose of the contents. The Divio links above do a great job at explaining each doc type. I'm simply sharing this idea for people who have never considered being more careful about how they label their docs and would like to start following general technical writing community practices. As a practicing technical writer I can tell you that the TW community mostly agrees upon what each doc type entails ("tutorials" and "references" have strong consensus; "guides" less so).
[+] [-] msie|5 years ago|reply
https://javascript.info/structure
[+] [-] stingraycharles|5 years ago|reply
Here’s an example great bike shed discussion from ~10y ago about whether or not to use semicolons with JavaScript.
“If you don’t understand how statements in JavaScript are terminated, then you just don’t know JavaScript very well, and shouldn’t write JavaScript programs professionally without supervision, and you definitely should not tell anyone else how to write their JavaScript programs.”
Those were the fun days! :)
[+] [-] gtsop|5 years ago|reply
If for any reason you absolutelly can't have these in place, better be safe and use semicolons.
Edit: for the "gotcha" explained in the link, prettier will automatically insert a semicolon before the array.
[+] [-] weeksie|5 years ago|reply
[+] [-] pknopf|5 years ago|reply
There was a big push for that a while back. The JavaScript community can be silly.
[+] [-] sneak|5 years ago|reply
It's nice to not waste a single braincycle on these things anymore.
[+] [-] flippinburgers|5 years ago|reply
[+] [-] austincheney|5 years ago|reply
[+] [-] simplify|5 years ago|reply
[+] [-] cgrealy|5 years ago|reply
[+] [-] halfmatthalfcat|5 years ago|reply
[+] [-] brundolf|5 years ago|reply
[+] [-] jerrygoyal|5 years ago|reply
[+] [-] bob1029|5 years ago|reply
[+] [-] vmurthy|5 years ago|reply
All parts together is $18 (epub + pdf). I am not a front-end developer so not much use for me personally but spreading the good word :)
https://javascript.info/ebook
[+] [-] robofanatic|5 years ago|reply
[+] [-] unknown|5 years ago|reply
[deleted]
[+] [-] kaycebasques|5 years ago|reply
[+] [-] boberoni|5 years ago|reply
I'm curious. How are my language preferences exposed through HTTP headers?
I think this was a charming way to request volunteers for translation, but I was a bit taken aback.
[+] [-] smarx007|5 years ago|reply
Edit: check out chrome://translate-internals/ if you are interested
[+] [-] lights0123|5 years ago|reply
[+] [-] jmt_|5 years ago|reply
[+] [-] croisillon|5 years ago|reply
[+] [-] sequoia|5 years ago|reply
[+] [-] pwdisswordfish4|5 years ago|reply
[deleted]
[+] [-] pachico|5 years ago|reply
[+] [-] MaxBarraclough|5 years ago|reply
The Loops section gives a very brief description of what loops are. This doesn't introduce anything of value to an experienced programmer, and it's nowhere near enough of an explanation for teaching imperative programming to a beginner.
Personally I'd suggest targeting experienced programmers. I only learnt JavaScript relatively recently, and I found it very frustrating that every JavaScript tutorial I could find was aimed at beginners (and that isn't an exaggeration).
[+] [-] emmanueloga_|5 years ago|reply
For as good as the TOC and layout is, there's always something I miss when I read books from a website. I miss the spatial context: how much material I already covered? How much is left?
I like the linearity of regular books (that includes PDFs). If the book is a website the next best thing for me is when the whole thing is just a single page. Worst thing are epubs :-p (hate the way the layout works with those and how slow epub readers tend to be).
ps. I saw I can buy a PDF of this site, but just commenting in general.
[+] [-] cercatrova|5 years ago|reply
[+] [-] polywock|5 years ago|reply
[+] [-] bovermyer|5 years ago|reply
As someone who doesn't use Javascript much... is there a way to force it to copy the current state of the original variable to the new variable, without it being a reference and without having to use something like lodash?
[+] [-] lighthazard|5 years ago|reply
[+] [-] rhengles|5 years ago|reply
One way to have a deep copy which shares nothing is const copy = JSON.parse(JSON.stringify(object)); but that may not always work. In short, copying a arbitrarily large object will probably waste memory, so it should be a little hard so you don't do it unless it's really necessary.
[+] [-] derivagral|5 years ago|reply
[0] e.g. https://immutable-js.github.io/immutable-js/
[+] [-] ianjsikes|5 years ago|reply
[+] [-] longnow|5 years ago|reply
> The ideal name for a variable is data. Use it everywhere you can.
There is one small comment at the top of the chapter, which says ‘Irony detected’. Is there really a whole chapter written Ironically? It would be very easy to read this and think it was real advice.
(And if it is real advice, and I’m completely misunderstanding, then I can’t possibly recommend this book).
[+] [-] alfonsodev|5 years ago|reply
I'm not sure now which sections are and aren't.
[+] [-] forgotmypw17|5 years ago|reply
[+] [-] austincheney|5 years ago|reply
[+] [-] markdown|5 years ago|reply
[+] [-] yudlejoza|5 years ago|reply
Intro section has no context, especially how this relates to Crockford's "the good parts".
Is it inspired by it, in conflict with it, a superset, a subset? How did newer standards affect it? how is 'modern' defined? How is 'now' defined?
[+] [-] ddoolin|5 years ago|reply
[+] [-] dmje|5 years ago|reply
[+] [-] jonnycomputer|5 years ago|reply
https://javascript.info/ninja-code
>Show your original thinking! Let the call of checkPermission return not true/false, but a complex object with the results of the check.
>Those developers who try to write if (checkPermission(..)), will wonder why it doesn’t work. Tell them: “Read the docs!”. And give this article.
[+] [-] z3t4|5 years ago|reply
The proper way is callback convention err. Then you can write if(!err) ...
[+] [-] weaksauce|5 years ago|reply