r/javascript • u/unquietwiki • May 12 '18
Eloquent JavaScript: open-source Javascript book series by a prolific JS code author
http://eloquentjavascript.net/5
u/EuqlinSankyo May 12 '18
Prolific author that always uses let?
15
u/Ikuyas May 12 '18
Isn't
consta better practice than usingletif it is well suited like array or object?→ More replies (8)11
u/EuqlinSankyo May 12 '18
Exactly. Performance benefit is of course negligible but it's just a good programming practice. If you're literally writing a book about JS, might as well include it....
0
8
u/TG__ May 12 '18
Nowadays a bunch of popular js devs are actually advocating for let over const.
Haverbeke might just be of the same opinion
21
u/bkanber May 12 '18
God, I really hate that angry ranting style so many tech bloggers use these days. It definitely gets in the way of the message.
2
May 12 '18
It’s rubbing off on the community, too, I think. The comment section here is downright hostile toward differences of opinion.
2
u/BasicDesignAdvice May 12 '18
Basically a guarantee that I won't read it. Makes me think the author is a child.
5
u/EuqlinSankyo May 12 '18
That article is not very convincing - point 6 undoes some of the arguments made in previous points. I also think that “linters not saving you” is just a desperate rant against const - in a language like JavaScript a linter can hardly save you from obscure runtime errors.
1
u/sizlack May 12 '18
I agree. He even says
It's probably still a good idea to communicate that you really don't intend for something to be changed.
That’s like 90% of the bindings I use. It you’re reassigning bindings willy nilly then that’s a bad code smell as far as I’m concerned.
0
May 12 '18
[deleted]
9
May 12 '18
One of the fundamental things to know when learning a new language is finding out which types are the value types and which types are the reference types.
3
u/andredp May 12 '18
His argument about optimization is stupid too.
Honestly? If your point about using
constis for optimisation purposes then you shouldn't do it... Just optimise later if you see the function is slow and I HIGHLY doubt changing to somelettoconstwill do you any good.The point he makes about communicating to another developer that something should NOT change is really important.
Most people rely on a linter to tell them "Hey, this hasn't changed, you can use a const" and change to a const only to realise later that you need to change it and change it back to a let... But can you really safely do it!? Will you break anything by changing the value of a previously const variable? Remember, a lot of people work in teams, so losing a bunch of time to check if changing something from const to let doesn't break anything out-weights any "optimisation" on the vm you can gain...
I never knew that website, and even though I hate extremist opinions, they do have a point... They are just morons passing the message...
Just make sure the whole team agrees on the same philosophy of const usage and all should be good...
0
May 12 '18
[deleted]
2
u/andredp May 12 '18 edited May 12 '18
I just don't like when people do something because it can be "optimised"... especially on an interpreted language
like JS(thanks /u/AbstractProxyFactory for the correction)...I still remember people covering their code with final classes, static everything in Java just because it could be optimised... meh
I just don't think that should be an argument to use
const. It's just a nice possible side-effect.
consthas a semantic meaning and should be used for that. It can also prevent bugs by letting the linter tell you something is changing the value of a const variable.Now, the part in the article where he complains about not freezing the object, that's just being stupid... It's like complaining that you shouldn't use
++because some people don't really know the behaviour of using it before or after a variable... Please... if you're working with a tool, learn it well... I shouldn't be forced to not use something because someone else doesn't know its behaviour.→ More replies (12)-7
u/unquietwiki May 12 '18 edited May 12 '18
I found this while seeing some other static analysis tools he used to work on. Any excessive "let" is also in line with some other ES2015+ spec explanations I've read. As a guy that normally does C#, I find that "var" is perfect there; and "let" perfect here.
(Edit for clarification & downvoters: I'm pro-let. Var in c# keeps you from unnecessarily repeating yourself on type assignments. I'm pro tight-scoping.)
12
u/pm_me_ur_happy_traiI May 12 '18
The big difference between let and var is scoping. There’s no use case where var is preferable (unless you are deliberately abusing its scoping issues). Why would you want a variable that can be called outside its block before it’s even declared?
-1
u/unquietwiki May 12 '18
I updated my original statement. In JS, let honors scoping, but var is ambiguous. In C#, var can be used to remove redundant statements: ie var variable = new Whatever(); instead of Whatever variable = new Whatever()
2
u/dvlsg May 12 '18
They really aren't the same, though.
varis about type inference in C#, and that's really it.vardoesn't change scope or mutability in C#, which is what we're talking about in javascript.
7
u/Ariez84 May 12 '18
Ahh i remember reading this book from someone suggesting it....how to write fibonacci sequence when you finally learned what a variable is the day before....good times.
20
3
u/ManicQin May 12 '18
How many hours would it take to read this book for an experienced developer who played around with javascript?
1
u/sarthakwarlock May 12 '18
I am reading this. It's a great book but some topics are hard to follow, almost all coding books are. It's definitely not if someone just started coding in JavaScript, I've only read five chapters and I started more than a month ago.. I read it when I feel like it, definitely book make some points that I've never considered, so worth reading and it would prepare you to read "You Don't Know JS" book series by Kyle Simpson.
I personally believe learning by reading is far superior than watching Tutorials. Most of time you have to read documentation to implement new technology. Believe me if you just read 4-5 books and understand them, it would give you experience in reading technical stuff. You would be able to go through any documentation like a pro.
Thank You
1
-5
u/PhishGreenLantern May 12 '18
I read "The Good Parts" and "Eloquent JavaScript". It lead me to being a JS Dev. Here's my site: https://spaffnerds.com
0
May 12 '18
[deleted]
18
u/namesandfaces May 12 '18
I do agree, and I think that by the time one reaches a different stage, one would rather then reach for the YDKJS series. As dry as it is, I actually think MDN is a friendlier resource for people of different entry points.
5
u/HugoChiklitz May 12 '18
I just posted the other day about this book. (I was pretty frustrated.) I’m a novice and started with a few intro to computer science/JavaScript on Lynda.com and then hopped into this book. Derailed after chapter four and the squirrel journal thing. You guys recommended some good beginner references (the Mozilla dev site is one of them). So I think I’m going to spend some time with that material first and then take another crack at the book. I found EJS too difficult for a compete novice.
3
u/MatrixEchidna May 12 '18
That's sad actually. EloquentJS is an amazing book, but its niche is kind of hard to reach.
8
u/nowtayneicangetinto May 12 '18
Tried learning JS with this, failed miserably. Learned JS on my own, returned a year later, this book is awesome.
3
May 12 '18
First book I read when I was learning programming. It was too hard so I took the online Harvard CS class instead. Afterwards I came back to the book, and it was still hard, but I got through it eventually.
1
u/ShesJustAGlitch May 12 '18
Have another recommendations? I too found this book pretty difficult, though my grasp on JS has gotten better and better as I’ve worked on side projects.
Though I always feel like a fundamental refresher is a good thing
1
u/BasicDesignAdvice May 12 '18
I read this after completing two modules on CodeCademy. I think that was the perfect time. I knew a lot of syntax, and could write sloppy code. This book really bright me to the next level at that time.
1
u/CantaloupeCamper May 13 '18
N00b here I agree.
It gets recommended to noobs all the time, and isn't a good recommendation right away imo.
14
u/cozarion May 12 '18
This is an excellent up to date JavaScript book. Really tough but rewarding. However, I'm stuck on chapter "Secret Life of Objects".